2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableDropdownOption
|
|
|
|
* Represents a single entry in an EditableRadioField
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fieldeditor
|
|
|
|
*/
|
|
|
|
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}]";
|
|
|
|
}
|
|
|
|
|
2009-01-28 06:59:23 +01:00
|
|
|
function populateFromPostData($data) {
|
2008-09-29 05:18:23 +02:00
|
|
|
$this->Title = $data['Title'];
|
2009-01-28 06:59:23 +01:00
|
|
|
if(isset($data['Default'])) {
|
|
|
|
$this->setField('Default', $data['Default']);
|
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
$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\"";
|
2009-01-22 21:55:58 +01:00
|
|
|
else
|
|
|
|
$disabled = '';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
|
|
|
if( $this->getField('Default') )
|
|
|
|
$default = " checked=\"checked\"";
|
2009-01-22 21:55:58 +01:00
|
|
|
else
|
|
|
|
$default = '';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
|
|
|
return "<input class=\"checkbox\" type=\"checkbox\" name=\"Fields[{$this->ParentID}][{$this->ID}][Default]\" value=\"1\"".$disabled.$default." />";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|