2009-04-17 04:26:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base Class for EditableOption Fields such as the ones used in
|
|
|
|
* dropdown fields and in radio check box groups
|
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
|
|
|
|
class EditableOption extends DataObject {
|
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $default_sort = "Sort";
|
2009-04-17 04:26:40 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $db = array(
|
2009-07-05 09:14:03 +02:00
|
|
|
"Name" => "Varchar(255)",
|
|
|
|
"Title" => "Varchar(255)",
|
2009-04-17 04:26:40 +02:00
|
|
|
"Default" => "Boolean",
|
|
|
|
"Sort" => "Int"
|
|
|
|
);
|
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $has_one = array(
|
2009-04-17 04:26:40 +02:00
|
|
|
"Parent" => "EditableMultipleOptionField",
|
|
|
|
);
|
2009-09-23 03:36:52 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $extensions = array(
|
2009-09-23 03:36:52 +02:00
|
|
|
"Versioned('Stage', 'Live')"
|
|
|
|
);
|
2009-04-17 04:26:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Template for the editing view of this option field
|
|
|
|
*/
|
|
|
|
public function EditSegment() {
|
|
|
|
return $this->renderWith('EditableOption');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Title Field for this object
|
|
|
|
*
|
|
|
|
* @return FormField
|
|
|
|
*/
|
|
|
|
public function TitleField() {
|
|
|
|
return new TextField("Fields[{$this->ParentID}][{$this->ID}][Title]", null, $this->Title );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of this field in the form
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
2009-05-22 01:31:46 +02:00
|
|
|
public function FieldName() {
|
2009-04-17 04:26:40 +02:00
|
|
|
return "Fields[{$this->ParentID}][{$this->ID}]";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate this option from the form field
|
|
|
|
*
|
|
|
|
* @param Array Data
|
|
|
|
*/
|
|
|
|
public function populateFromPostData($data) {
|
|
|
|
$this->Title = (isset($data['Title'])) ? $data['Title'] : "";
|
|
|
|
$this->Default = (isset($data['Default'])) ? $data['Default'] : "";
|
|
|
|
$this->Sort = (isset($data['Sort'])) ? $data['Sort'] : 0;
|
|
|
|
$this->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make this option readonly
|
|
|
|
*/
|
|
|
|
public function ReadonlyOption() {
|
|
|
|
$this->readonly = true;
|
|
|
|
return $this->EditSegment();
|
|
|
|
}
|
2013-05-08 09:08:21 +02:00
|
|
|
|
|
|
|
public function getEscapedTitle() {
|
2013-06-04 08:17:23 +02:00
|
|
|
return Convert::raw2att($this->Title);
|
2013-05-08 09:08:21 +02:00
|
|
|
}
|
|
|
|
}
|