2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set of radio buttons designed to emulate a dropdown.
|
|
|
|
* It even uses the same constructor as a dropdown field.
|
|
|
|
*/
|
|
|
|
class OptionsetField extends DropdownField {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new optionset field.
|
|
|
|
* @param name The field name
|
|
|
|
* @param title The field title
|
|
|
|
* @param source An map of the dropdown items
|
|
|
|
* @param value The current value
|
|
|
|
* @param form The parent form
|
|
|
|
*/
|
|
|
|
function __construct($name, $title = "", $source = array(), $value = "", $form = null) {
|
|
|
|
parent::__construct($name, $title, $source, $value, $form);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a <ul> containing sets of radio buttons and labels. The IDs are set to
|
|
|
|
* FieldID_ItemKey, where ItemKey is the key with all non-alphanumerics removed.
|
|
|
|
*/
|
|
|
|
function Field() {
|
|
|
|
$options = '';
|
|
|
|
$odd = 0;
|
|
|
|
foreach($this->source as $key => $value) {
|
|
|
|
$itemID = $this->id() . "_" . ereg_replace('[^a-zA-Z0-9]+','',$key);
|
|
|
|
|
|
|
|
if($key == $this->value/* || $useValue */) {
|
|
|
|
$useValue = false;
|
|
|
|
$checked = " checked=\"checked\"";
|
|
|
|
} else {
|
|
|
|
$checked="";
|
|
|
|
}
|
|
|
|
|
|
|
|
$odd = ($odd + 1) % 2;
|
|
|
|
$extraClass = $odd ? "odd" : "even";
|
|
|
|
$extraClass .= " val" . str_replace(' ','',$key);
|
2007-11-25 22:19:30 +01:00
|
|
|
$disabled = $this->disabled ? 'disabled="disabled"' : $disable = '';
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-11-23 02:10:19 +01:00
|
|
|
$options .= "<li class=\"".$extraClass."\"><input id=\"$itemID\" name=\"$this->name\" type=\"radio\" value=\"$key\"$checked $disabled/> <label for=\"$itemID\">$value</label></li>\n";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
$id = $this->id();
|
2007-11-25 22:19:30 +01:00
|
|
|
return "<ul id=\"$id\" class=\"optionset {$this->extraClass()}\">\n$options</ul>\n";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-11-23 02:10:19 +01:00
|
|
|
|
|
|
|
protected $disabled = false;
|
|
|
|
function setDisabled($val) {
|
|
|
|
$this->disabled = $val;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function performReadonlyTransformation() {
|
|
|
|
// Source and values are DataObject sets.
|
|
|
|
$items = $this->source;
|
|
|
|
$field = new LookupField($this->name,$this->title ? $this->title : "" ,$items,$this->value);
|
|
|
|
$field->setForm($this->form);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ExtraOptions() {
|
|
|
|
return new DataObjectSet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|