Fix bug 477287 - with Cache, Provider for Google Calendar loses alarms and categories on event edit / alarms and categories cannot be added to existing events.a=philipp
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 27 Oct 2011 10:45:14 +0200
changeset 8958 359d0ea7f24d6495b9eded00581bde7360a4c0d4
parent 8957 177be7c55fd4ecfb416fba0507fddab3839faffb
child 8959 913cc0cb37f9e76de6b1c9a8deeb28a27352fd8d
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs477287
Fix bug 477287 - with Cache, Provider for Google Calendar loses alarms and categories on event edit / alarms and categories cannot be added to existing events.a=philipp
calendar/providers/gdata/components/calGoogleCalendar.js
calendar/providers/gdata/components/calGoogleUtils.js
--- a/calendar/providers/gdata/components/calGoogleCalendar.js
+++ b/calendar/providers/gdata/components/calGoogleCalendar.js
@@ -342,17 +342,17 @@ calGoogleCalendar.prototype = {
             // Check if we have a session. If not, then the user has canceled
             // the login prompt.
             this.ensureSession();
 
             // Add the calendar to the item, for later use.
             aItem.calendar = this.superCalendar;
 
             var request = new calGoogleRequest(this);
-            var xmlEntry = ItemToXMLEntry(aItem,
+            var xmlEntry = ItemToXMLEntry(aItem, this,
                                           this.session.userName,
                                           this.session.fullName);
 
             request.type = request.ADD;
             request.uri = this.fullUri.spec;
             request.setUploadData("application/atom+xml; charset=UTF-8", xmlEntry);
             request.operationListener = aListener;
             request.calendar = this;
@@ -424,17 +424,17 @@ calGoogleCalendar.prototype = {
             var request = new calGoogleRequest(this.session);
 
             // We need to clone the new item, its possible that ItemToXMLEntry
             // will modify the item. For example, if the item is organized by
             // someone else, we cannot save alarms on it and they should
             // therefore not be added in the returned item. 
             var newItem = aNewItem.clone();
 
-            var xmlEntry = ItemToXMLEntry(newItem,
+            var xmlEntry = ItemToXMLEntry(newItem, this,
                                           this.session.userName,
                                           this.session.fullName);
 
             if (aOldItem.parentItem != aOldItem &&
                 !aOldItem.parentItem.recurrenceInfo.getExceptionFor(aOldItem.startDate)) {
 
                 // In this case we are modifying an occurence, not deleting it
                 request.type = request.ADD;
--- a/calendar/providers/gdata/components/calGoogleUtils.js
+++ b/calendar/providers/gdata/components/calGoogleUtils.js
@@ -218,24 +218,25 @@ function passwordManagerRemove(aUsername
     return cal.auth.passwordManagerRemove(aUsername, aUsername, "Google Calendar");
 }
 
 /**
  * ItemToXMLEntry
  * Converts a calIEvent to a string of xml data.
  *
  * @param aItem         The item to convert
+ * @param aCalendar     The calendar to use, this must be a calIGoogleCalendar
  * @param aAuthorEmail  The email of the author of the event
  * @param aAuthorName   The full name of the author of the event
  * @return              The xml data of the item
  */
-function ItemToXMLEntry(aItem, aAuthorEmail, aAuthorName) {
+function ItemToXMLEntry(aItem, aCalendar, aAuthorEmail, aAuthorName) {
 
     var selfIsOrganizer = (!aItem.organizer ||
-                            aItem.organizer.id == "mailto:" + aItem.calendar.googleCalendarName);
+                            aItem.organizer.id == "mailto:" + aCalendar.googleCalendarName);
 
     function addExtendedProperty(aName, aValue) {
         if (!selfIsOrganizer || !aValue) {
             // We can't set extended properties if we are not the organizer,
             // discard. Also, if the value is null/false, we can delete the
             // extended property by not adding it.
             return;
         }
@@ -451,16 +452,18 @@ function ItemToXMLEntry(aItem, aAuthorEm
 
     // gd:visibility
     var privacy = aItem.privacy || "default";
     entry.gd::visibility.@value = kEVENT_SCHEMA + privacy.toLowerCase();
 
     // categories
     // Google does not support categories natively, but allows us to store data
     // as an "extendedProperty", so we do here
+    cal.WARN("CAT: " + aItem.getCategories({}).toSource() + " = " +
+             categoriesArrayToString(aItem.getCategories({})));
     addExtendedProperty("X-MOZ-CATEGORIES",
                         categoriesArrayToString(aItem.getCategories({})));
 
     // gd:recurrence
     if (aItem.recurrenceInfo) {
         try {
             const kNEWLINE = "\r\n";
             var icalString;