Fix bug 702613 - user is allowed to set invalid end time in events. r=philipp
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 09 Aug 2012 20:28:43 +0200
changeset 13229 7ce307d297ff36486fbaaa0b3dc0d78fe13176eb
parent 13228 2e67745910d86294d583d1bf69941e86f3c29a20
child 13230 71eae60afbf60a611153125ea034c2f92e9ed511
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs702613
Fix bug 702613 - user is allowed to set invalid end time in events. r=philipp
calendar/base/content/dialogs/calendar-event-dialog.js
calendar/test/mozmill/eventDialog/testEventDialog.js
calendar/test/mozmill/eventDialog/testEventDialogModificationPrompt.js
calendar/test/mozmill/eventDialog/testUTF8.js
calendar/test/mozmill/recurrence/testAnnualRecurrence.js
calendar/test/mozmill/recurrence/testBiweeklyRecurrence.js
calendar/test/mozmill/recurrence/testDailyRecurrence.js
calendar/test/mozmill/recurrence/testLastDayOfMonthRecurrence.js
calendar/test/mozmill/recurrence/testWeeklyNRecurrence.js
calendar/test/mozmill/recurrence/testWeeklyUntilRecurrence.js
calendar/test/mozmill/recurrence/testWeeklyWithExceptionRecurrence.js
calendar/test/mozmill/recurrenceRotated/testAnnualRecurrence.js
calendar/test/mozmill/recurrenceRotated/testBiweeklyRecurrence.js
calendar/test/mozmill/recurrenceRotated/testDailyRecurrence.js
calendar/test/mozmill/recurrenceRotated/testLastDayOfMonthRecurrence.js
calendar/test/mozmill/recurrenceRotated/testWeeklyNRecurrence.js
calendar/test/mozmill/recurrenceRotated/testWeeklyUntilRecurrence.js
calendar/test/mozmill/recurrenceRotated/testWeeklyWithExceptionRecurrence.js
calendar/test/mozmill/testAlarmDefaultValue.js
calendar/test/mozmill/views/testDayView.js
calendar/test/mozmill/views/testMonthView.js
calendar/test/mozmill/views/testMultiweekView.js
calendar/test/mozmill/views/testTaskView.js
calendar/test/mozmill/views/testWeekView.js
--- a/calendar/base/content/dialogs/calendar-event-dialog.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog.js
@@ -17,16 +17,17 @@ var gIsReadOnly = false;
 var gPrivacy = null;
 var gAttachMap = {};
 var gPriority = 0;
 var gStatus = "NONE";
 var gConfirmCancel = true;
 var gLastRepeatSelection = 0;
 var gIgnoreUpdate = false;
 var gShowTimeAs = null;
+var gWarning = false;
 
 var eventDialogQuitObserver = {
   observe: function(aSubject, aTopic, aData) {
     // Check whether or not we want to veto the quit request (unless another
     // observer already did.
     if (aTopic == "quit-application-requested" &&
         (aSubject instanceof Components.interfaces.nsISupportsPRBool) &&
         !aSubject.data)
@@ -230,29 +231,30 @@ function onEventDialogUnload() {
 /**
  * Handler function to be called when the accept button is pressed.
  *
  * @return      Returns true if the window should be closed
  */
 function onAccept() {
     dispose();
     onCommandSave(true);
-    return true;
+    return !gWarning;
 }
 
 /**
  * Asks the user if the item should be saved and does so if requested. If the
  * user cancels, the window should stay open.
  *
  * XXX Could possibly be consolidated into onCancel()
  *
  * @return    Returns true if the window should be closed.
  */
 function onCommandCancel() {
-    if (!isItemChanged()) {
+    // Allow closing if the item has not changed and no warning dialog has to be showed.
+    if (!isItemChanged() && !gWarning) {
         return true;
     }
 
     var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                         .getService(Components.interfaces.nsIPromptService);
 
     var promptTitle = calGetString("calendar",
                                    isEvent(window.calendarItem) ?
@@ -279,16 +281,18 @@ function onCommandCancel() {
                                          null,
                                          null,
                                          {});
     switch (choice) {
         case 0: // Save
             onCommandSave(true);
             return true;
         case 2: // Don't save
+            // Don't show any warning dialog when closing without saving.
+            gWarning = false;
             return true;
         default: // Cancel
             return false;
     }
 }
 
 /**
  * Handler function to be called when the cancel button is pressed.
@@ -297,17 +301,20 @@ function onCommandCancel() {
 function onCancel() {
     // The datepickers need to remove the focus in order to trigger the
     // validation of the values just edited, with the keyboard, but not yet
     // confirmed (i.e. not followed by a click, a tab or enter keys pressure).
     document.documentElement.focus();
 
     if (!gConfirmCancel || (gConfirmCancel && onCommandCancel())) {
         dispose();
-        return true;
+        // Don't allow closing the dialog when the user inputs a wrong
+        // date then closes the dialog and answers with "Save" in
+        // the "Save Event" dialog.
+        return !gWarning;
     }
     return false;
 }
 
 /**
  * Sets up all dialog controls from the information of the passed item.
  *
  * @param item      The item to parse information out of.
@@ -617,23 +624,25 @@ function dateTimeControls2State(aStartDa
             warning = true;
         }
     }
 
     updateDateTime();
     updateTimezone();
 
     if (warning) {
+        gWarning = true;
         var callback = function func() {
             var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                                 .getService(Components.interfaces.nsIPromptService);
             promptService.alert(
                 null,
                 document.title,
                 calGetString("calendar", "warningEndBeforeStart"));
+                gWarning = false;
         }
         setTimeout(callback, 1);
     }
 }
 
 /**
  * Updates the entry date checkboxes, used for example when choosing an alarm:
  * the entry date needs to be checked in that case.
@@ -2302,16 +2311,21 @@ function saveItem() {
  *                                save prompt just before the window is closing.
  */
 function onCommandSave(aIsClosing) {
     // The datepickers need to remove the focus in order to trigger the
     // validation of the values just edited, with the keyboard, but not yet
     // confirmed (i.e. not followed by a click, a tab or enter keys pressure).
     document.documentElement.focus();
 
+    // Don't save if a warning dialog about a wrong input date must be showed.
+    if (gWarning) {
+        return;
+    }
+
     let originalItem = window.calendarItem;
     let item = saveItem();
     let calendar = getCurrentCalendar();
 
     item.makeImmutable();
     // Set the item for now, the callback below will set the full item when the
     // call succeeded
     window.calendarItem = item;