Bug 1140802 - Deleting an event in the view after opening the event dialog via double-click causes a MODIFICATION_FAILED error. r=philipp
authorMatthew Mecca <matthew.mecca@gmail.com>
Thu, 12 Mar 2015 10:26:33 +0100
changeset 17644 10ae8ea49f4ea4f828600b99e024b39a16dd3b4e
parent 17643 edafc098a2a36540f08f96b9e24d2c27cd4b769e
child 17645 05be474b042d42f358e5b4204ae05947639091e0
push id10863
push userarchaeopteryx@coole-files.de
push dateThu, 12 Mar 2015 09:30:05 +0000
treeherdercomm-central@10ae8ea49f4e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1140802
Bug 1140802 - Deleting an event in the view after opening the event dialog via double-click causes a MODIFICATION_FAILED error. r=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);