Bug 1140802 - Deleting an event in the view after opening the event dialog via double-click causes a MODIFICATION_FAILED error. r=philipp,a=philipp
authorMatthew Mecca <matthew.mecca@gmail.com>
Mon, 23 Mar 2015 13:59:54 +0100
changeset 19703 8b4abb999d29b5524b6d51aae200513bb4cf013d
parent 19702 2947dd6c9e500ae202747a6da880d31acf81999d
child 19704 0d49514e9ba2c1bc6401e2c66e7d13f1cc02aa5c
push id1384
push usermozilla@kewis.ch
push dateMon, 23 Mar 2015 13:00:14 +0000
treeherdercomm-aurora@8b4abb999d29 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp, philipp
bugs1140802
Bug 1140802 - Deleting an event in the view after opening the event dialog via double-click causes a MODIFICATION_FAILED error. r=philipp,a=philipp
calendar/base/content/calendar-views.js
--- a/calendar/base/content/calendar-views.js
+++ b/calendar/base/content/calendar-views.js
@@ -34,94 +34,21 @@ var calendarViewController = {
             setDefaultItemValues(item, aCalendar, aStartTime, aEndTime);
             item.title = calGetString("calendar", "newEvent");
             doTransaction('add', item, item.calendar, null, null);
         } else {
             createEventWithDialog(aCalendar, aStartTime, null, null, null, aForceAllday);
         }
     },
 
-    pendingJobs: [],
-
-    /**
-     * In order to initiate a modification for the occurrence passed as argument
-     * we create an object that records the necessary details and store it in an
-     * internal array ('pendingJobs'). this way we're in a position to terminate
-     * any pending modification if need should be.
-     *
-     * @param aOccurrence       The occurrence to create the pending
-     *                            modification for.
-     */
-    createPendingModification: function (aOccurrence) {
-        // finalize a (possibly) pending modification. this will notify
-        // an open dialog to save any outstanding modifications.
-        aOccurrence = this.finalizePendingModification(aOccurrence);
-
-        // XXX TODO logic to ask for which occurrence to modify is currently in
-        // modifyEventWithDialog, since the type of transactions done depend on
-        // this. This in turn makes the aOccurrence here be potentially wrong, I
-        // haven't seen it used anywhere though.
-        var pendingModification = {
-            controller: this,
-            item: aOccurrence,
-            finalize: null,
-            dispose: function() {
-                var array = this.controller.pendingJobs;
-                for (var i=0; i<array.length; i++) {
-                    if (array[i] == this) {
-                        array.splice(i,1);
-                        break;
-                    }
-                }
-            }
-        }
-
-        this.pendingJobs.push(pendingModification);
-
-        modifyEventWithDialog(aOccurrence, pendingModification, true);
-    },
-
-    /**
-     * Iterate the list of pending modifications and see if the occurrence
-     * passed as argument is currently about to be modified (event dialog is
-     * open with the item in question). If this should be the case we call
-     * finalize() in order to bring the dialog down and avoid dataloss.
-     *
-     * @param aOccurrence       The occurrence to finalize the modification for.
-     */
-    finalizePendingModification: function (aOccurrence) {
-
-      for each (var job in this.pendingJobs) {
-          var item = job.item;
-          var parent = item.parent;
-          if ((item.hashId == aOccurrence.hashId) ||
-              (item.parentItem.hashId == aOccurrence.hashId) ||
-              (item.hashId == aOccurrence.parentItem.hashId)) {
-              // terminate() will most probably create a modified item instance.
-              aOccurrence = job.finalize();
-              break;
-        }
-      }
-
-      return aOccurrence;
-    },
-
     /**
      * Modifies the given occurrence
      * @see calICalendarViewController
      */
     modifyOccurrence: function (aOccurrence, aNewStartTime, aNewEndTime, aNewTitle) {
-        let dlg = cal.findItemWindow(aOccurrence);
-        if (dlg) {
-            dlg.focus();
-            return;
-        }
-
-        aOccurrence = this.finalizePendingModification(aOccurrence);
-
         // if modifying this item directly (e.g. just dragged to new time),
         // then do so; otherwise pop up the dialog
         if (aNewStartTime || aNewEndTime || aNewTitle) {
             let instance = aOccurrence.clone();
 
             if (aNewTitle) {
                 instance.title = aNewTitle;
             }
@@ -148,17 +75,17 @@ var calendarViewController = {
                     if (aNewEndTime && instance.dueDate) {
                         instance.dueDate = aNewEndTime;
                     }
                 }
             }
 
             doTransaction('modify', instance, instance.calendar, aOccurrence, null);
         } else {
-            this.createPendingModification(aOccurrence);
+            modifyEventWithDialog(aOccurrence, null, true);
         }
     },
 
     /**
      * Deletes the given occurrences
      * @see calICalendarViewController
      */
     deleteOccurrences: function (aCount,
@@ -205,17 +132,16 @@ var calendarViewController = {
                     break;
                 }
             }
 
             // Now some dirty work: Make sure more than one occurrence can be
             // deleted by saving the recurring items and removing occurrences as
             // they come in. If this is not an occurrence, we can go ahead and
             // delete the whole item.
-            itemToDelete = this.finalizePendingModification(itemToDelete);
             if (itemToDelete.parentItem.hashId != itemToDelete.hashId) {
                 var savedItem = getSavedItem(itemToDelete);
                 savedItem.newItem.recurrenceInfo
                          .removeOccurrenceAt(itemToDelete.recurrenceId);
                 // Dont start the transaction yet. Do so later, in case the
                 // parent item gets modified more than once.
             } else {
                 doTransaction('delete', itemToDelete, itemToDelete.calendar, null, null);