silverstripe-framework/forms/EditableCheckboxOption.php
Hayden Smith 4a5d9b03f8 Moved Sapphire module to open source path
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@39001 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-07-19 10:40:28 +00:00

76 lines
1.8 KiB
PHP
Executable File

<?php
/**
* EditableDropdownOption
* Represents a single entry in an EditableRadioField
*/
class EditableCheckboxOption extends DataObject {
static $default_sort = "Sort";
// add required here?
static $db = array(
"Name" => "Varchar",
"Title" => "Varchar",
"Default" => "Boolean",
"Sort" => "Int"
);
static $has_one = array(
"Parent" => "EditableCheckboxGroupField",
);
static $singular_name = "Checkbox option";
static $plural_name = "Checkbox options";
function EditSegment() {
return $this->renderWith('EditableFormFieldOption');
}
function TitleField() {
return new TextField( "Fields[{$this->ParentID}][{$this->ID}][Title]", null, $this->Title );
}
function Name() {
return "Fields[{$this->ParentID}][{$this->ID}]";
}
function populateFromPostData( $data ) {
$this->Title = $data['Title'];
$this->setField('Default', $data['Default']);
$this->Sort = $data['Sort'];
$this->write();
}
function Option() {
// return new radio field
/*$title = Convert::raw2att( $this->Title );
$default = "";
if( $this->getField('Default') )
$default = '+';
else
$default = '-';
//Debug::show($this);
return '<input type="text" name="Fields['.$this->ParentID.']['.$this->ID.'][Title]" value="'.$default.$title.'" />';*/
return $this->EditSegment();
}
function ReadonlyOption() {
$this->readonly = true;
return $this->EditSegment();
}
function DefaultSelect() {
if( $this->readonly )
$disabled = " disabled=\"disabled\"";
if( $this->getField('Default') )
$default = " checked=\"checked\"";
return "<input class=\"checkbox\" type=\"checkbox\" name=\"Fields[{$this->ParentID}][{$this->ID}][Default]\" value=\"1\"".$disabled.$default." />";
}
}
?>