mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 351957, 312084, 361642: removing temp file, fixing preview without calendar view, waiting for async provider response
This commit is contained in:
parent
fd9bd016a5
commit
4620b10226
@ -42,20 +42,32 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var gTempFile = null;
|
||||
|
||||
var gPrintSettings = null;
|
||||
|
||||
function getCalendarView()
|
||||
{
|
||||
var theView = window.opener.currentView();
|
||||
if (!theView.startDay) {
|
||||
theView = null;
|
||||
}
|
||||
return theView;
|
||||
}
|
||||
|
||||
function loadCalendarPrintDialog()
|
||||
{
|
||||
// set the datepickers to the currently selected dates
|
||||
var theView = window.opener.currentView();
|
||||
document.getElementById("start-date-picker").value = theView.startDay.jsDate;
|
||||
document.getElementById("end-date-picker").value = theView.endDay.jsDate;
|
||||
|
||||
if (!theView.getSelectedItems({}).length) {
|
||||
var theView = getCalendarView();
|
||||
if (theView) {
|
||||
document.getElementById("start-date-picker").value = theView.startDay.jsDate;
|
||||
document.getElementById("end-date-picker").value = theView.endDay.jsDate;
|
||||
} else {
|
||||
document.getElementById("printCurrentViewRadio").setAttribute("disabled", true);
|
||||
}
|
||||
if (!theView || !theView.getSelectedItems({}).length) {
|
||||
document.getElementById("selected").setAttribute("disabled", true);
|
||||
}
|
||||
document.getElementById(theView ? "printCurrentViewRadio" : "custom-range")
|
||||
.setAttribute("selected", true);
|
||||
|
||||
// Get a list of formatters
|
||||
var contractids = new Array();
|
||||
@ -83,11 +95,6 @@ function loadCalendarPrintDialog()
|
||||
self.focus();
|
||||
}
|
||||
|
||||
function unloadCalendarPrintDialog()
|
||||
{
|
||||
gTempFile.remove(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the settings from the dialog's UI widgets.
|
||||
* notifies an Object with title, layoutCId, eventList, start, and end
|
||||
@ -103,7 +110,7 @@ function getEventsAndDialogSettings(receiverFunc)
|
||||
settings.end = null;
|
||||
settings.eventList = null;
|
||||
|
||||
var theView = window.opener.currentView();
|
||||
var theView = getCalendarView();
|
||||
switch (document.getElementById("view-field").selectedItem.value) {
|
||||
case 'currentview':
|
||||
case '': //just in case
|
||||
@ -157,7 +164,7 @@ function getEventsAndDialogSettings(receiverFunc)
|
||||
* updates the HTML in the iframe accordingly. This is also called when a
|
||||
* dialog UI element has changed, since we'll want to refresh the preview.
|
||||
*/
|
||||
function refreshHtml()
|
||||
function refreshHtml(finishFunc)
|
||||
{
|
||||
getEventsAndDialogSettings(
|
||||
function getEventsAndDialogSettings_response(settings) {
|
||||
@ -170,43 +177,55 @@ function refreshHtml()
|
||||
var printformatter = Components.classes[settings.layoutCId]
|
||||
.createInstance(Components.interfaces.calIPrintFormatter);
|
||||
|
||||
// Fail-safe check to not init twice, to prevent leaking files
|
||||
if (gTempFile) {
|
||||
gTempFile.remove(false);
|
||||
}
|
||||
const nsIFile = Components.interfaces.nsIFile;
|
||||
var dirService = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties);
|
||||
gTempFile = dirService.get("TmpD", nsIFile);
|
||||
gTempFile.append("calendarPrint.html");
|
||||
gTempFile.createUnique(nsIFile.NORMAL_FILE_TYPE, 0600); // 0600 = -rw-------
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var tempUri = ioService.newFileURI(gTempFile);
|
||||
|
||||
var stream = Components.classes["@mozilla.org/network/file-output-stream;1"]
|
||||
.createInstance(Components.interfaces.nsIFileOutputStream);
|
||||
|
||||
var html = "";
|
||||
try {
|
||||
// 0x2A = PR_TRUNCATE, PR_CREATE_FILE, PR_WRONLY
|
||||
// 0600 = -rw-------
|
||||
stream.init(gTempFile, 0x2A, 0600, 0);
|
||||
printformatter.formatToHtml(stream,
|
||||
var pipe = Components.classes["@mozilla.org/pipe;1"]
|
||||
.createInstance(Components.interfaces.nsIPipe);
|
||||
pipe.init(true, true, 0, 0, null);
|
||||
printformatter.formatToHtml(pipe.outputStream,
|
||||
settings.start,
|
||||
settings.end,
|
||||
settings.eventList.length,
|
||||
settings.eventList,
|
||||
settings.title);
|
||||
stream.close();
|
||||
pipe.outputStream.close();
|
||||
// convert byte-array to UTF-8 string:
|
||||
var convStream =
|
||||
Components.classes["@mozilla.org/intl/converter-input-stream;1"]
|
||||
.createInstance(Components.interfaces.nsIConverterInputStream);
|
||||
convStream.init(pipe.inputStream, "UTF-8", 0,
|
||||
Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
|
||||
try {
|
||||
var portion = {};
|
||||
while (convStream.readString(-1, portion)) {
|
||||
html += portion.value;
|
||||
}
|
||||
} finally {
|
||||
convStream.close();
|
||||
}
|
||||
} catch (e) {
|
||||
dump("printDialog::refreshHtml:" + e + "\n");
|
||||
Components.utils.reportError(e);
|
||||
}
|
||||
document.getElementById('content').contentDocument.documentElement.innerHTML = html;
|
||||
|
||||
document.getElementById("content").contentWindow.location = tempUri.spec;
|
||||
if (finishFunc) {
|
||||
finishFunc();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function printAndClose()
|
||||
{
|
||||
refreshHtml(
|
||||
function finish() {
|
||||
PrintUtils.print();
|
||||
document.getElementById("calendar-new-printwindow").cancelDialog();
|
||||
});
|
||||
return false; // leave open
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when once a date has been selected in the datepicker.
|
||||
*/
|
||||
|
@ -63,12 +63,11 @@
|
||||
id="calendar-new-printwindow"
|
||||
title="&calendar.print.window.title;"
|
||||
onload="loadCalendarPrintDialog()"
|
||||
onunload="unloadCalendarPrintDialog()"
|
||||
buttons="accept,cancel"
|
||||
buttonlabelaccept="&calendar.print.button.label;"
|
||||
buttonaccesskeyaccept="&calendar.print.accesskey;"
|
||||
defaultButton="accept"
|
||||
ondialogaccept="PrintUtils.print();"
|
||||
ondialogaccept="return printAndClose();"
|
||||
ondialogcancel="return true;"
|
||||
persist="screenX screenY width height"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
@ -122,7 +121,7 @@
|
||||
<radiogroup id="view-field" oncommand="refreshHtml();">
|
||||
<radio id="printCurrentViewRadio"
|
||||
label="&calendar.print.currentview.label;"
|
||||
value="currentview" selected="true" />
|
||||
value="currentview"/>
|
||||
<radio id="selected" label="&calendar.print.selected.label;"
|
||||
value="selected"/>
|
||||
<radio id="custom-range" label="&calendar.print.custom.label;"
|
||||
|
Loading…
Reference in New Issue
Block a user