2016-04-27 01:02:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorBoolEditField
|
|
|
|
extends PhabricatorEditField {
|
|
|
|
|
2016-04-28 00:40:35 +02:00
|
|
|
private $options;
|
2016-10-31 19:38:35 +01:00
|
|
|
private $asCheckbox;
|
2016-04-28 00:40:35 +02:00
|
|
|
|
|
|
|
public function setOptions($off_label, $on_label) {
|
|
|
|
$this->options = array(
|
|
|
|
'0' => $off_label,
|
|
|
|
'1' => $on_label,
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOptions() {
|
|
|
|
return $this->options;
|
|
|
|
}
|
|
|
|
|
2016-10-31 19:38:35 +01:00
|
|
|
public function setAsCheckbox($as_checkbox) {
|
|
|
|
$this->asCheckbox = $as_checkbox;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAsCheckbox() {
|
|
|
|
return $this->asCheckbox;
|
|
|
|
}
|
|
|
|
|
2016-04-27 01:02:57 +02:00
|
|
|
protected function newControl() {
|
2016-04-28 00:40:35 +02:00
|
|
|
$options = $this->getOptions();
|
|
|
|
|
|
|
|
if (!$options) {
|
|
|
|
$options = array(
|
|
|
|
'0' => pht('False'),
|
|
|
|
'1' => pht('True'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-31 19:38:35 +01:00
|
|
|
if ($this->getAsCheckbox()) {
|
|
|
|
$key = $this->getKey();
|
|
|
|
$value = $this->getValueForControl();
|
|
|
|
$checkbox_key = $this->newHTTPParameterType()
|
|
|
|
->getCheckboxKey($key);
|
|
|
|
$id = $this->getControlID();
|
|
|
|
|
|
|
|
$control = id(new AphrontFormCheckboxControl())
|
|
|
|
->setCheckboxKey($checkbox_key)
|
|
|
|
->addCheckbox($key, '1', $options['1'], $value, $id);
|
|
|
|
} else {
|
|
|
|
$control = id(new AphrontFormSelectControl())
|
|
|
|
->setOptions($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $control;
|
2016-04-27 01:02:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function newHTTPParameterType() {
|
|
|
|
return new AphrontBoolHTTPParameterType();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function newConduitParameterType() {
|
|
|
|
return new ConduitBoolParameterType();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|