mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-15 03:12:41 +01:00
f7b0c09ac4
Summary: This feels a little cleaner: - Clean up transaction log a bit. - Use a checkbox instead of a two-option dropdown. This is a little messy because the browser doesn't send anything if the user submits a form with an un-clicked checkbox. We now send a dummy value ("Hey, there's definitely a checkbox in this form!") so the server can figure out what to do. Test Plan: - Edited all-dayness of an event. - Viewed transaction log. Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D16776
66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
|
|
final class PhabricatorBoolEditField
|
|
extends PhabricatorEditField {
|
|
|
|
private $options;
|
|
private $asCheckbox;
|
|
|
|
public function setOptions($off_label, $on_label) {
|
|
$this->options = array(
|
|
'0' => $off_label,
|
|
'1' => $on_label,
|
|
);
|
|
return $this;
|
|
}
|
|
|
|
public function getOptions() {
|
|
return $this->options;
|
|
}
|
|
|
|
public function setAsCheckbox($as_checkbox) {
|
|
$this->asCheckbox = $as_checkbox;
|
|
return $this;
|
|
}
|
|
|
|
public function getAsCheckbox() {
|
|
return $this->asCheckbox;
|
|
}
|
|
|
|
protected function newControl() {
|
|
$options = $this->getOptions();
|
|
|
|
if (!$options) {
|
|
$options = array(
|
|
'0' => pht('False'),
|
|
'1' => pht('True'),
|
|
);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
protected function newHTTPParameterType() {
|
|
return new AphrontBoolHTTPParameterType();
|
|
}
|
|
|
|
protected function newConduitParameterType() {
|
|
return new ConduitBoolParameterType();
|
|
}
|
|
|
|
}
|