From bc3b0ff960cedc526f21d1f075fb3e94537ac5cb Mon Sep 17 00:00:00 2001 From: "mattwillis%gmail.com" Date: Thu, 7 Sep 2006 15:01:51 +0000 Subject: [PATCH] bug 334468 - Adds date and imip-bar to meeting requests. patch by ctalbert, r1=lilmatt, r2=dmose --- .../lightningTextCalendarConverter.js | 141 +++++++++++++----- calendar/lightning/jar.mn | 1 + .../chrome/lightning/lightning.properties | 8 + 3 files changed, 112 insertions(+), 38 deletions(-) diff --git a/calendar/lightning/components/lightningTextCalendarConverter.js b/calendar/lightning/components/lightningTextCalendarConverter.js index 4edcf00a0e53..b77d76056cfc 100644 --- a/calendar/lightning/components/lightningTextCalendarConverter.js +++ b/calendar/lightning/components/lightningTextCalendarConverter.js @@ -20,6 +20,7 @@ * * Contributor(s): * Mike Shaver + * Clint Talbert * * 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 @@ -35,69 +36,134 @@ * * ***** END LICENSE BLOCK ***** */ -const CI = Components.interfaces; +const Cc = Components.classes; +const Ci = Components.interfaces; function makeTableRow(val) { return "" + val[0] + "" + val[1] + "\n"; } -function makeButton(type, content) { - return ""; +function getLightningStringBundle() +{ + var svc = Cc["@mozilla.org/intl/stringbundle;1"] + .getService(Ci.nsIStringBundleService); + return svc.createBundle("chrome://lightning/locale/lightning.properties"); } -function startForm(calendarData) { - var form = "
\n"; - form += "\n"; - // We use escape instead of encodeURI*, because we need to deal with single quotes, sigh - form += "\n"; - return form; +function createHtmlTableSection(label, text) +{ + var tblRow = + +

{label}

+ + +

{text}

+ + ; + return tblRow; +} + +function createHtml(event) +{ + // Creates HTML using the Node strings in the properties file + var stringBundle = getLightningStringBundle(); + var html; + if (stringBundle) { + // Using e4x javascript support here + html = + + + + + + + +
+ + ; + // Create header row + var labelText = stringBundle.GetStringFromName("imipHtml.header"); + html.body.table.appendChild( + + +

{labelText}

+ + + ); + if (event.title) { + labelText = stringBundle.GetStringFromName("imipHtml.summary"); + html.body.table.appendChild(createHtmlTableSection(labelText, + event.title)); + } + + var eventLocation = event.getProperty("LOCATION"); + if (eventLocation) { + labelText = stringBundle.GetStringFromName("imipHtml.location"); + html.body.table.appendChild(createHtmlTableSection(labelText, + eventLocation)); + } + + var labelText = stringBundle.GetStringFromName("imipHtml.when"); + html.body.table.appendChild(createHtmlTableSection(labelText, + event.startDate.jsDate.toLocaleString())); + + if (event.organizer && + (event.organizer.commonName || event.organizer.id)) { + labelText = stringBundle.GetStringFromName("imipHtml.organizer"); + var orgname = event.organizer.commonName || event.organizer.id; + html.body.table.appendChild(createHtmlTableSection(labelText, orgname)); + } + + var eventDescription = event.getProperty("DESCRIPTION"); + if (eventDescription) { + labelText = stringBundle.GetStringFromName("imipHtml.description"); + html.body.table.appendChild(createHtmlTableSection(labelText, + eventDescription)); + } + } + + return html; } function ltnMimeConverter() { } ltnMimeConverter.prototype = { QueryInterface: function (aIID) { - if (!aIID.equals(CI.nsISupports) && - !aIID.equals(CI.nsISimpleMimeConverter)) - throw Components.interfaces.NS_ERROR_NO_INTERFACE; + if (!aIID.equals(Ci.nsISupports) && + !aIID.equals(Ci.nsISimpleMimeConverter)) + throw Ci.NS_ERROR_NO_INTERFACE; return this; }, convertToHTML: function(contentType, data) { - // dump("converting " + contentType + " to HTML\n"); - - var event = Components.classes["@mozilla.org/calendar/event;1"] - .createInstance(CI.calIEvent); + var event = Cc["@mozilla.org/calendar/event;1"] + .createInstance(Ci.calIEvent); event.icalString = data; + var html = createHtml(event); - var html = "\n"; - html += "
\n"; - html += startForm(data); - html += "\n"; - var organizer = event.organizer; - var rows = [["Invitation from", "" + - organizer.commonName + ""], - ["Topic:", event.title], - ["Start:", event.startDate.jsDate.toLocaleTimeString()], - ["End:", event.endDate.jsDate.toLocaleTimeString()]]; - html += rows.map(makeTableRow).join("\n"); - html += "\n"; - html += "
"; - html += makeButton("accept", "Accept meeting") + " "; - html += makeButton("decline", "Decline meeting") + " "; - html += "
\n\n
"; + try { + // Bug 351610: This mechanism is a little flawed + var itipItem = Cc["@mozilla.org/calendar/itip-item;1"] + .createInstance(Ci.calIItipItem); + itipItem.initialize(data); + var observer = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); + if (observer) { + observer.notifyObservers(itipItem, "onITipItemCreation", 0); + } + } catch (e) { + Components.utils.reportError("Cannot Create iTIP Item: " + e); + } - // dump("Generated HTML:\n\n" + html + "\n\n"); return html; - }, - + } }; var myModule = { registerSelf: function (compMgr, fileSpec, location, type) { debug("*** Registering Lightning text/calendar handler\n"); - compMgr = compMgr.QueryInterface(CI.nsIComponentRegistrar); + compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar); compMgr.registerFactoryLocation(this.myCID, "Lightning text/calendar handler", this.myContractID, @@ -106,7 +172,7 @@ var myModule = { type); var catman = Components.classes["@mozilla.org/categorymanager;1"] - .getService(CI.nsICategoryManager); + .getService(Ci.nsICategoryManager); catman.addCategoryEntry("simple-mime-converters", "text/calendar", this.myContractID, true, true); @@ -144,4 +210,3 @@ function NSGetModule(compMgr, fileSpec) { return myModule; } - diff --git a/calendar/lightning/jar.mn b/calendar/lightning/jar.mn index 8343e648d2c3..60fae934a0ae 100644 --- a/calendar/lightning/jar.mn +++ b/calendar/lightning/jar.mn @@ -94,6 +94,7 @@ calendar-en-US.jar: classic.jar: #expand skin/classic/lightning/lightning.css (themes/__THEME__/lightning.css) +#expand skin/classic/lightning/imip.css (themes/__THEME__/imip.css) #expand skin/classic/calendar/prevnextarrow.png (/calendar/sunbird/themes/__THEME__/sunbird/prevnextarrow.png) #expand skin/classic/calendar/pageupdown.png (/calendar/sunbird/themes/__THEME__/sunbird/pageupdown.png) #expand skin/classic/calendar/calendar-toolbar.css (/calendar/base/themes/__THEME__/calendar-toolbar.css) diff --git a/calendar/locales/en-US/chrome/lightning/lightning.properties b/calendar/locales/en-US/chrome/lightning/lightning.properties index 7a744502e4db..727c9bfb60d5 100644 --- a/calendar/locales/en-US/chrome/lightning/lightning.properties +++ b/calendar/locales/en-US/chrome/lightning/lightning.properties @@ -39,3 +39,11 @@ agendaToday=Today agendaTomorrow=Tomorrow agendaSoon=Soon + +# Html event display in message +imipHtml.header=Event Invitation +imipHtml.summary=Title: +imipHtml.location=Location: +imipHtml.when=When: +imipHtml.organizer=Organizer: +imipHtml.description=Description: