Fix bug 554267 - Deleting a single item of an recurring event, does not delete the alarm of this event.. r=philipp
authorMatthew Mecca <matthew.mecca@gmail.com>
Sat, 02 Apr 2011 12:17:00 +0200
changeset 7958 c53e83988e2680c2c654a437d37bbfb89cd92be1
parent 7957 067609fdfcb2e5b29940911544d52eff2d0a275d
child 7959 74f08dc06935562c20f08699ee13b806a9c32303
push id50
push usermozilla@kewis.ch
push dateTue, 19 Jul 2011 20:04:29 +0000
treeherdercomm-beta@aee08b4d6cf3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs554267
Fix bug 554267 - Deleting a single item of an recurring event, does not delete the alarm of this event.. r=philipp
calendar/base/src/calAlarmService.js
--- a/calendar/base/src/calAlarmService.js
+++ b/calendar/base/src/calAlarmService.js
@@ -18,16 +18,17 @@
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Stuart Parmenter <stuart.parmenter@oracle.com>
  *   Joey Minta <jminta@gmail.com>
  *   Daniel Boelzle <daniel.boelzle@sun.com>
  *   Philipp Kewisch <mozilla@kewis.ch>
  *   Martin Schroeder <mschroeder@mozilla.x-home.org>
+ *   Matthew Mecca <matthew.mecca@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -74,43 +75,49 @@ function calAlarmService() {
             // ignore any onLoad events until initial getItems() call of startup has finished:
             if (calendar && this.alarmService.mLoadedCalendars[calendar.id]) {
                 // a refreshed calendar signals that it has been reloaded
                 // (and cannot notify detailed changes), thus reget all alarms of it:
                 this.alarmService.initAlarms([calendar]);
             }
         },
 
-        onAddItem: function(aItem) {
-            let occs = [];
-            if (aItem.recurrenceInfo) {
+        getOccurrencesInRange: function(aItem) {
+            if (aItem && aItem.recurrenceInfo) {
                 let start = this.alarmService.mRangeEnd.clone();
                 // We search 1 month in each direction for alarms.  Therefore,
                 // we need to go back 2 months from the end to get this right.
                 start.month -= 2;
-                occs = aItem.recurrenceInfo.getOccurrences(start, this.alarmService.mRangeEnd, 0, {});
+                return aItem.recurrenceInfo.getOccurrences(start, this.alarmService.mRangeEnd, 0, {});
             } else {
-                occs = [aItem];
+                return [aItem];
             }
+        },
+        onAddItem: function(aItem) {
+            let occs = this.getOccurrencesInRange(aItem);
 
             // Add an alarm for each occurrence
             occs.forEach(this.alarmService.addAlarmsForItem,
                          this.alarmService);
         },
         onModifyItem: function(aNewItem, aOldItem) {
             if (!aNewItem.recurrenceId) {
                 // deleting an occurrence currently calls modifyItem(newParent, *oldOccurrence*)
                 aOldItem = aOldItem.parentItem;
             }
 
             this.onDeleteItem(aOldItem);
             this.onAddItem(aNewItem);
         },
         onDeleteItem: function(aDeletedItem) {
-            this.alarmService.removeAlarmsForItem(aDeletedItem);
+            let occs = this.getOccurrencesInRange(aDeletedItem);
+
+            // Remove alarm for each occurrence
+            occs.forEach(this.alarmService.removeAlarmsForItem,
+                         this.alarmService);
         },
         onError: function(aCalendar, aErrNo, aMessage) {},
         onPropertyChanged: function(aCalendar, aName, aValue, aOldValue) {
             switch (aName) {
                 case "suppressAlarms":
                 case "disabled":
                     this.alarmService.initAlarms([aCalendar]);
                     break;
@@ -454,17 +461,17 @@ calAlarmService.prototype = {
                     this.alarmFired(aItem, alarm);
                 }
             }
         }
     },
 
     removeAlarmsForItem: function cAS_removeAlarmsForItem(aItem) {
         // make sure already fired alarms are purged out of the alarm window:
-        this.mObservers.notify("onRemoveAlarmsByItem", [aItem]);
+        this.mObservers.notify("onRemoveAlarmsByItem", [aItem.parentItem]);
         // Purge alarms specifically for this item (i.e exception)
         for each (let alarm in aItem.getAlarms({})) {
             this.removeTimer(aItem, alarm);
         }
     },
 
     addTimer: function cAS_addTimer(aItem, aAlarm, aTimeout) {
         this.mTimerMap[aItem.calendar.id] =