2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-01-08 07:37:50 +01:00
|
|
|
|
|
|
|
/**
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fieldeditor
|
2008-01-08 07:37:50 +01:00
|
|
|
*/
|
|
|
|
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
* EditableDropdownOption
|
|
|
|
* Represents a single entry in an EditableDropdown
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fieldeditor
|
|
|
|
*/
|
|
|
|
class EditableDropdownOption extends DataObject {
|
|
|
|
protected $readonly;
|
|
|
|
|
|
|
|
function ReadonlyOption() {
|
|
|
|
$this->readonly = true;
|
|
|
|
return $this->EditSegment();
|
|
|
|
}
|
|
|
|
|
|
|
|
function isReadonly() {
|
|
|
|
return $this->readonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
static $default_sort = "Sort";
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// add required here?
|
|
|
|
static $db = array(
|
|
|
|
"Name" => "Varchar",
|
|
|
|
"Title" => "Varchar",
|
|
|
|
"Default" => "Boolean",
|
|
|
|
"Sort" => "Int"
|
|
|
|
);
|
|
|
|
static $has_one = array(
|
|
|
|
"Parent" => "EditableDropdown",
|
|
|
|
);
|
2008-01-09 05:18:36 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $singular_name = 'Dropdown option';
|
|
|
|
static $plural_name = 'Dropdown 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->Sort = $data['Sort'];
|
|
|
|
$this->write();
|
|
|
|
}
|
2008-01-09 05:18:36 +01:00
|
|
|
|
|
|
|
function Option() {
|
|
|
|
// return new radio field
|
|
|
|
/*$title = $this->Title;
|
|
|
|
|
|
|
|
$default = "";
|
|
|
|
|
|
|
|
if( $this->getField('Default') )
|
|
|
|
$default = 'class="default"';
|
|
|
|
|
|
|
|
//Debug::show($this);
|
|
|
|
return '<input type="text" name="Fields['.$this->ParentID.']['.$this->ID.'][Title]" value="'.$title.'" '.$default.' />';*/
|
|
|
|
|
|
|
|
return $this->EditSegment();
|
|
|
|
}
|
|
|
|
|
|
|
|
function DefaultSelect() {
|
|
|
|
$disabled = ($this->readonly) ? " disabled=\"disabled\"" : '';
|
|
|
|
|
2008-05-13 05:07:43 +02:00
|
|
|
$default = ($this->Parent()->getField('Default') == $this->ID) ? " checked=\"checked\"" : "";
|
2008-01-09 05:18:36 +01:00
|
|
|
|
|
|
|
return "<input class=\"radio\" type=\"radio\" name=\"Fields[{$this->ParentID}][Default]\" value=\"{$this->ID}\"".$disabled.$default." />";
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
?>
|