1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Hide time controls when editing all-day Calendar events

Summary:
Ref T11326. When an event is all-day, hide the time controls for the start/end dates. These aren't used and aren't helpful/useful.

This got a little more complicated than it used to be because EditEngine forms may have only some of these controls present.

Test Plan: Edited an all-day event; edited a normal event; swapped an event between normal and all-day.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11326

Differential Revision: https://secure.phabricator.com/D16327
This commit is contained in:
epriestley 2016-07-26 11:20:09 -07:00
parent c6ba4272d7
commit e5256bd815
4 changed files with 67 additions and 10 deletions

View file

@ -212,4 +212,45 @@ final class PhabricatorCalendarEventEditEngine
return $fields;
}
protected function willBuildEditForm($object, array $fields) {
$all_day_field = idx($fields, 'isAllDay');
$start_field = idx($fields, 'start');
$end_field = idx($fields, 'end');
if ($all_day_field) {
$is_all_day = $all_day_field->getValueForTransaction();
$control_ids = array();
if ($start_field) {
$control_ids[] = $start_field->getControlID();
}
if ($end_field) {
$control_ids[] = $end_field->getControlID();
}
Javelin::initBehavior(
'event-all-day',
array(
'allDayID' => $all_day_field->getControlID(),
'controlIDs' => $control_ids,
));
} else {
$is_all_day = $object->getIsAllDay();
}
if ($is_all_day) {
if ($start_field) {
$start_field->setHideTime(true);
}
if ($end_field) {
$end_field->setHideTime(true);
}
}
return $fields;
}
}

View file

@ -1176,6 +1176,8 @@ abstract class PhabricatorEditEngine
$controller = $this->getController();
$request = $controller->getRequest();
$fields = $this->willBuildEditForm($object, $fields);
$form = id(new AphrontFormView())
->setUser($viewer)
->addHiddenInput('editEngine', 'true');
@ -1210,6 +1212,10 @@ abstract class PhabricatorEditEngine
return $form;
}
protected function willBuildEditForm($object, array $fields) {
return $fields;
}
private function buildEditFormActionButton($object) {
if (!$this->isEngineConfigurable()) {
return null;

View file

@ -4,6 +4,7 @@ final class PhabricatorEpochEditField
extends PhabricatorEditField {
private $allowNull;
private $hideTime;
public function setAllowNull($allow_null) {
$this->allowNull = $allow_null;
@ -14,9 +15,19 @@ final class PhabricatorEpochEditField
return $this->allowNull;
}
public function setHideTime($hide_time) {
$this->hideTime = $hide_time;
return $this;
}
public function getHideTime() {
return $this->hideTime;
}
protected function newControl() {
return id(new AphrontFormDateControl())
->setAllowNull($this->getAllowNull())
->setIsTimeDisabled($this->getHideTime())
->setViewer($this->getViewer());
}
@ -26,9 +37,7 @@ final class PhabricatorEpochEditField
}
protected function newConduitParameterType() {
// TODO: This isn't correct, but we don't have any methods which use this
// yet.
return new ConduitIntParameterType();
return new ConduitEpochParameterType();
}
}

View file

@ -2,15 +2,16 @@
* @provides javelin-behavior-event-all-day
*/
JX.behavior('event-all-day', function(config) {
var checkbox = JX.$(config.allDayID);
JX.DOM.listen(checkbox, 'change', null, function() {
var start = JX.$(config.startDateID);
var end = JX.$(config.endDateID);
var all_day = JX.$(config.allDayID);
JX.DOM.alterClass(start, 'no-time', checkbox.checked);
JX.DOM.alterClass(end, 'no-time', checkbox.checked);
JX.DOM.listen(all_day, 'change', null, function() {
var is_all_day = !!parseInt(all_day.value, 10);
for (var ii = 0; ii < config.controlIDs.length; ii++) {
var control = JX.$(config.controlIDs[ii]);
JX.DOM.alterClass(control, 'no-time', is_all_day);
}
});
});