From 47051643c76cd1244e5f07d9280e6503114ef896 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Sun, 7 Jun 2015 15:57:19 -0700 Subject: [PATCH] Show informative errors when attempting to set a recurrence end date on a non-recurring event. Summary: Fixes T8458, Show informative errors when attempting to set a recurrence end date on a non-recurring event. Test Plan: Create new event, set recurrence end date via date-picker without setting the "is recurring" checkbox, and attempt to save. Should get error saying there cannot be a recurrence end date on a non-recurring event. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T8458 Differential Revision: https://secure.phabricator.com/D13192 --- ...PhabricatorCalendarEventEditController.php | 2 +- .../editor/PhabricatorCalendarEventEditor.php | 28 +++++++++++++-- .../calendar/behavior-recurring-edit.js | 36 ++++++++++++++----- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php index bb5812a09a..72422e03e2 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php @@ -324,7 +324,7 @@ final class PhabricatorCalendarEventEditController ->setID($recurrence_end_date_id) ->setIsTimeDisabled(true) ->setAllowNull(true) - ->setIsDisabled(!$is_recurring); + ->setIsDisabled($recurrence_end_date_value->isDisabled()); $recurrence_frequency_select = id(new AphrontFormSelectControl()) ->setName('frequency') diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php index 712dd8945d..79b5946f04 100644 --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php @@ -265,10 +265,20 @@ final class PhabricatorCalendarEventEditor protected function validateAllTransactions( PhabricatorLiskDAO $object, array $xactions) { - $start_date_xaction = PhabricatorCalendarEventTransaction::TYPE_START_DATE; - $end_date_xaction = PhabricatorCalendarEventTransaction::TYPE_END_DATE; + $start_date_xaction = + PhabricatorCalendarEventTransaction::TYPE_START_DATE; + $end_date_xaction = + PhabricatorCalendarEventTransaction::TYPE_END_DATE; + $is_recurrence_xaction = + PhabricatorCalendarEventTransaction::TYPE_RECURRING; + $recurrence_end_xaction = + PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE; + $start_date = $object->getDateFrom(); $end_date = $object->getDateTo(); + $recurrence_end = $object->getRecurrenceEndDate(); + $is_recurring = $object->getIsRecurring(); + $errors = array(); foreach ($xactions as $xaction) { @@ -276,6 +286,10 @@ final class PhabricatorCalendarEventEditor $start_date = $xaction->getNewValue()->getEpoch(); } else if ($xaction->getTransactionType() == $end_date_xaction) { $end_date = $xaction->getNewValue()->getEpoch(); + } else if ($xaction->getTransactionType() == $recurrence_end_xaction) { + $recurrence_end = $xaction->getNewValue(); + } else if ($xaction->getTransactionType() == $is_recurrence_xaction) { + $is_recurring = $xaction->getNewValue(); } } if ($start_date > $end_date) { @@ -287,6 +301,16 @@ final class PhabricatorCalendarEventEditor null); } + if ($recurrence_end && !$is_recurring) { + $type = + PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE; + $errors[] = new PhabricatorApplicationTransactionValidationError( + $type, + pht('Invalid'), + pht('Event must be recurring to have a recurrence end date.'). + null); + } + return $errors; } diff --git a/webroot/rsrc/js/application/calendar/behavior-recurring-edit.js b/webroot/rsrc/js/application/calendar/behavior-recurring-edit.js index 6ce29bdf6b..7e75e3b838 100644 --- a/webroot/rsrc/js/application/calendar/behavior-recurring-edit.js +++ b/webroot/rsrc/js/application/calendar/behavior-recurring-edit.js @@ -5,17 +5,37 @@ JX.behavior('recurring-edit', function(config) { var checkbox = JX.$(config.isRecurring); + var frequency = JX.$(config.frequency); + var end_date = JX.$(config.recurrenceEndDate); + + var end_date_checkbox = JX.DOM.find(end_date, 'input', 'calendar-enable'); JX.DOM.listen(checkbox, 'change', null, function() { - var frequency = JX.$(config.frequency); - var end_date = JX.$(config.recurrenceEndDate); - - frequency.disabled = checkbox.checked ? false : true; - end_date.disabled = checkbox.checked ? false : true; - - if (end_date.disabled) { - JX.DOM.alterClass(end_date, 'datepicker-disabled', !checkbox.checked); + if (checkbox.checked) { + enableRecurring(); + } else { + disableRecurring(); } }); + JX.DOM.listen(end_date, 'change', null, function() { + if (end_date_checkbox.checked) { + enableRecurring(); + } + }); + + function enableRecurring() { + checkbox.checked = true; + frequency.disabled = false; + end_date.disabled = false; + } + + function disableRecurring() { + checkbox.checked = false; + frequency.disabled = true; + end_date.disabled = true; + end_date_checkbox.checked = false; + + JX.DOM.alterClass(end_date, 'datepicker-disabled', true); + } });