Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 138 lines (117 sloc) 3.269 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
<?php
/**
* Single checkbox field.
* @package forms
* @subpackage fields-basic
*/
class CheckboxField extends FormField {

protected $disabled;

function setValue($value) {
$this->value = ($value) ? 1 : 0;
}

function dataValue() {
return ($this->value) ? 1 : 0;
}

function Value() {
return ($this->value) ? 1 : 0;
}

function Field() {
$attributes = array(
'type' => 'checkbox',
'class' => ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $this->Name(),
'value' => 1,
'checked' => $this->value ? 'checked' : '',
'tabindex' => $this->getTabIndex()
);

if($this->disabled) $attributes['disabled'] = 'disabled';

return $this->createTag('input', $attributes);
}

/**
* Checkboxes use the RightLabelledFieldHolder template, to put the field on the left
* and the label on the right. See {@link FormField::FieldHolder} for more information about
* how FieldHolder works.
*/
function FieldHolder() {
if($this->labelLeft) {
return parent::FieldHolder();
} else {
extract($this->getXMLValues(array( 'Name', 'Field', 'Title', 'Message', 'MessageType' )),
EXTR_SKIP);
$messageBlock = empty($Message) ? '' : "<span class=\"message $MessageType\">$Message</span>";
$Type = $this->XML_val('Type');
$extraClass = $this->XML_val('extraClass');
return <<<HTML
<p id="$Name" class="field $Type $extraClass">
$Field
<label class="right" for="{$this->id()}">$Title</label>
$messageBlock
</p>
HTML;

}
}

function useLabelLeft( $labelLeft = true ) {
$this->labelLeft = $labelLeft;
}

/**
* Returns a restricted field holder used within things like FieldGroups
*/
function SmallFieldHolder() {
$result = $this->Field();
if($t = $this->Title()) {
$result .= "<label for=\"" . $this->id() ."\">$t</label> ";
}
return $result;
}

/**
* Returns a readonly version of this field
*/

function performReadonlyTransformation() {
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
$field->setForm($this->form);
return $field;
}

function performDisabledTransformation() {
$clone = clone $this;
$clone->setDisabled(true);
return $clone;
}
}

/**
* Readonly version of a checkbox field - "Yes" or "No".
* @package forms
* @subpackage fields-basic
*/
class CheckboxField_Readonly extends ReadonlyField {
function performReadonlyTransformation() {
return clone $this;
}

function setValue($val) {
$this->value = (int)($val) ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No');
}
}

/**
* Single checkbox field, disabled
* @package forms
* @subpackage fields-basic
*/
class CheckboxField_Disabled extends CheckboxField {

protected $disabled = true;

/**
* Returns a single checkbox field - used by templates.
*/
function Field() {
$attributes = array(
'type' => 'checkbox',
'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $this->Name(),
'tabindex' => $this->getTabIndex(),
'checked' => ($this->value) ? 'checked' : false,
'disabled' => 'disabled'
);

return $this->createTag('input', $attributes);
}
}
?>
Something went wrong with that request. Please try again.