From e5256bd815844d34eb0bd7df0c964b0992f0e526 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 26 Jul 2016 11:20:09 -0700 Subject: [PATCH] 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 --- .../PhabricatorCalendarEventEditEngine.php | 41 +++++++++++++++++++ .../editengine/PhabricatorEditEngine.php | 6 +++ .../editfield/PhabricatorEpochEditField.php | 15 +++++-- .../calendar/behavior-event-all-day.js | 15 +++---- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php index 3e97cb2f5e..5fa6e95732 100644 --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php @@ -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; + } } diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php index 181369a58f..2805162336 100644 --- a/src/applications/transactions/editengine/PhabricatorEditEngine.php +++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php @@ -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; diff --git a/src/applications/transactions/editfield/PhabricatorEpochEditField.php b/src/applications/transactions/editfield/PhabricatorEpochEditField.php index 36c7be861c..9ac9726593 100644 --- a/src/applications/transactions/editfield/PhabricatorEpochEditField.php +++ b/src/applications/transactions/editfield/PhabricatorEpochEditField.php @@ -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(); } } diff --git a/webroot/rsrc/js/application/calendar/behavior-event-all-day.js b/webroot/rsrc/js/application/calendar/behavior-event-all-day.js index a8bd7da7a8..1121759e3c 100644 --- a/webroot/rsrc/js/application/calendar/behavior-event-all-day.js +++ b/webroot/rsrc/js/application/calendar/behavior-event-all-day.js @@ -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); + } }); });