Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editfield/PhabricatorBoolEditField.php
<?php | <?php | ||||
final class PhabricatorBoolEditField | final class PhabricatorBoolEditField | ||||
extends PhabricatorEditField { | extends PhabricatorEditField { | ||||
private $options; | private $options; | ||||
private $asCheckbox; | |||||
public function setOptions($off_label, $on_label) { | public function setOptions($off_label, $on_label) { | ||||
$this->options = array( | $this->options = array( | ||||
'0' => $off_label, | '0' => $off_label, | ||||
'1' => $on_label, | '1' => $on_label, | ||||
); | ); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getOptions() { | public function getOptions() { | ||||
return $this->options; | return $this->options; | ||||
} | } | ||||
public function setAsCheckbox($as_checkbox) { | |||||
$this->asCheckbox = $as_checkbox; | |||||
return $this; | |||||
} | |||||
public function getAsCheckbox() { | |||||
return $this->asCheckbox; | |||||
} | |||||
protected function newControl() { | protected function newControl() { | ||||
$options = $this->getOptions(); | $options = $this->getOptions(); | ||||
if (!$options) { | if (!$options) { | ||||
$options = array( | $options = array( | ||||
'0' => pht('False'), | '0' => pht('False'), | ||||
'1' => pht('True'), | '1' => pht('True'), | ||||
); | ); | ||||
} | } | ||||
return id(new AphrontFormSelectControl()) | 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); | ->setOptions($options); | ||||
} | } | ||||
return $control; | |||||
} | |||||
protected function newHTTPParameterType() { | protected function newHTTPParameterType() { | ||||
return new AphrontBoolHTTPParameterType(); | return new AphrontBoolHTTPParameterType(); | ||||
} | } | ||||
protected function newConduitParameterType() { | protected function newConduitParameterType() { | ||||
return new ConduitBoolParameterType(); | return new ConduitBoolParameterType(); | ||||
} | } | ||||
} | } |