2012-05-30 20:48:24 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-09-18 18:13:11 +04:00
|
|
|
|
2012-07-26 18:47:06 +04:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
2010-12-11 00:46:47 +03:00
|
|
|
Components.utils.import("resource://calendar/modules/calUtils.jsm");
|
2012-07-26 18:47:06 +04:00
|
|
|
Components.utils.import("resource://calendar/modules/calXMLUtils.jsm");
|
2008-09-18 18:13:11 +04:00
|
|
|
|
2012-07-26 18:47:06 +04:00
|
|
|
/**
|
|
|
|
* HTML Export Plugin
|
|
|
|
*/
|
2008-09-18 18:13:11 +04:00
|
|
|
function calHtmlExporter() {
|
|
|
|
}
|
|
|
|
|
2010-12-11 00:46:47 +03:00
|
|
|
calHtmlExporter.prototype = {
|
|
|
|
classID: Components.ID("{72d9ab35-9b1b-442a-8cd0-ae49f00b159b}"),
|
2012-07-26 18:47:06 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.calIExporter]),
|
2010-12-11 00:46:47 +03:00
|
|
|
|
2012-07-26 18:47:06 +04:00
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: Components.ID("{72d9ab35-9b1b-442a-8cd0-ae49f00b159b}"),
|
|
|
|
contractID: "@mozilla.org/calendar/export;1?type=html",
|
|
|
|
classDescription: "Calendar HTML Exporter",
|
|
|
|
interfaces: [Components.interfaces.calIExporter]
|
|
|
|
}),
|
2010-12-11 00:46:47 +03:00
|
|
|
|
|
|
|
getFileTypes: function getFileTypes(aCount) {
|
|
|
|
aCount.value = 1;
|
|
|
|
let wildmat = '*.html; *.htm';
|
|
|
|
let label = cal.calGetString("calendar", 'filterHtml', [wildmat]);
|
2012-07-26 18:47:06 +04:00
|
|
|
return [{
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.calIFileType]),
|
|
|
|
defaultExtension: 'html',
|
|
|
|
extensionFilter: wildmat,
|
|
|
|
description: label
|
|
|
|
}];
|
2010-12-11 00:46:47 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
exportToStream: function html_exportToStream(aStream, aCount, aItems, aTitle) {
|
2012-07-26 18:47:06 +04:00
|
|
|
let document = cal.xml.parseFile("chrome://calendar/skin/printing/calHtmlExport.html");
|
|
|
|
let itemContainer = document.getElementById("item-container");
|
|
|
|
document.getElementById("title").textContent = aTitle || cal.calGetString("calendar", "HTMLTitle");
|
2010-12-11 00:46:47 +03:00
|
|
|
|
|
|
|
// Sort aItems
|
2012-07-26 18:47:06 +04:00
|
|
|
aItems.sort(function(a, b) {
|
2010-12-11 00:46:47 +03:00
|
|
|
let start_a = a[cal.calGetStartDateProp(a)];
|
|
|
|
if (!start_a) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
let start_b = b[cal.calGetStartDateProp(b)];
|
|
|
|
if (!start_b) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return start_a.compare(start_b);
|
2012-07-26 18:47:06 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
for each (let item in aItems) {
|
|
|
|
let itemNode = document.getElementById("item-template").cloneNode(true);
|
|
|
|
itemNode.removeAttribute("id");
|
|
|
|
|
|
|
|
function setupTextRow(classKey, propValue, prefixKey) {
|
|
|
|
if (propValue) {
|
|
|
|
let prefix = cal.calGetString("calendar", prefixKey);
|
|
|
|
itemNode.querySelector("." + classKey + "key").textContent = prefix;
|
|
|
|
itemNode.querySelector("." + classKey).textContent = propValue;
|
|
|
|
} else {
|
|
|
|
let row = itemNode.querySelector("." + classKey + "row");
|
|
|
|
if (row.nextSibling instanceof Components.interfaces.nsIDOMText) {
|
|
|
|
row.parentNode.removeChild(row.nextSibling);
|
|
|
|
}
|
|
|
|
row.parentNode.removeChild(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-11 00:46:47 +03:00
|
|
|
let startDate = item[cal.calGetStartDateProp(item)];
|
|
|
|
let endDate = item[cal.calGetEndDateProp(item)];
|
2012-07-26 18:47:06 +04:00
|
|
|
if (startDate || endDate) {
|
2010-12-11 00:46:47 +03:00
|
|
|
// This is a task with a start or due date, format accordingly
|
2012-07-26 18:47:06 +04:00
|
|
|
let prefixWhen = cal.calGetString("calendar", "htmlPrefixWhen");
|
|
|
|
itemNode.querySelector(".intervalkey").textContent = prefixWhen;
|
|
|
|
|
|
|
|
let startNode = itemNode.querySelector(".dtstart");
|
|
|
|
let dateString = cal.getDateFormatter().formatItemInterval(item);
|
|
|
|
startNode.setAttribute("title", (startDate ? startDate.icalString : "none"));
|
|
|
|
startNode.textContent = dateString;
|
|
|
|
} else {
|
|
|
|
let row = itemNode.querySelector(".intervalrow");
|
|
|
|
row.parentNode.removeChild(row);
|
|
|
|
if (row.nextSibling instanceof Components.interfaces.nsIDOMText) {
|
|
|
|
row.parentNode.removeChild(row.nextSibling);
|
|
|
|
}
|
2010-12-11 00:46:47 +03:00
|
|
|
}
|
2008-09-18 18:13:11 +04:00
|
|
|
|
2012-07-26 18:47:06 +04:00
|
|
|
let itemTitle = (item.isCompleted ? cal.calGetString("calendar", "htmlTaskCompleted", [item.title]) : item.title);
|
|
|
|
setupTextRow("summary", itemTitle, "htmlPrefixTitle");
|
2010-12-11 00:46:47 +03:00
|
|
|
|
2012-07-26 18:47:06 +04:00
|
|
|
setupTextRow("location", item.getProperty("LOCATION"), "htmlPrefixLocation");
|
|
|
|
setupTextRow("description", item.getProperty("DESCRIPTION"), "htmlPrefixDescription");
|
|
|
|
|
|
|
|
itemContainer.appendChild(itemNode);
|
2008-09-18 18:13:11 +04:00
|
|
|
}
|
|
|
|
|
2012-07-26 18:47:06 +04:00
|
|
|
let templates = document.getElementById("templates");
|
|
|
|
templates.parentNode.removeChild(templates);
|
|
|
|
|
|
|
|
// Convert the javascript string to an array of bytes, using the utf8 encoder
|
2010-12-11 00:46:47 +03:00
|
|
|
let convStream = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
|
|
|
convStream.init(aStream, 'UTF-8', 0, 0x0000);
|
2012-07-26 18:47:06 +04:00
|
|
|
convStream.writeString(cal.xml.serializeDOM(document));
|
2010-12-11 00:46:47 +03:00
|
|
|
}
|
2008-09-18 18:13:11 +04:00
|
|
|
};
|