Fix bug 561550 - Disabling Events/Tasks checkbox in Print Preview dialog sets calendar to read-only [Error: Bad aItemFilter passed to getItems]. r=mmecca
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 21 Jul 2011 07:54:00 +0200
changeset 8785 8cd8084c08e99aab5bfba38e22d168e63beb3ad4
parent 8784 71929579880ee2319d98b9351c77bcbe64ef4da9
child 8786 2a3da6d15c356719179a67a6519425cb0fb7b8b2
push id158
push userbugzilla@standard8.plus.com
push dateTue, 27 Sep 2011 19:18:14 +0000
treeherdercomm-beta@e47b99c61e4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmmecca
bugs561550
Fix bug 561550 - Disabling Events/Tasks checkbox in Print Preview dialog sets calendar to read-only [Error: Bad aItemFilter passed to getItems]. r=mmecca
calendar/base/content/dialogs/calendar-print-dialog.js
calendar/base/content/dialogs/calendar-print-dialog.xul
--- a/calendar/base/content/dialogs/calendar-print-dialog.js
+++ b/calendar/base/content/dialogs/calendar-print-dialog.js
@@ -45,16 +45,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource://calendar/modules/calUtils.jsm");
+
 /**
  * Gets the calendar view from the opening window
  */
 function getCalendarView() {
     let theView = window.opener.currentView();
     if (!theView.startDay) {
         theView = null;
     }
@@ -217,16 +219,23 @@ function getFilter(settings) {
 }
 
 /**
  * Looks at the selections the user has made (start date, layout, etc.), and
  * 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(finishFunc) {
+    if (document.documentElement.getButton("accept").disabled) {
+        // If the accept button is disabled, then something wants us to not
+        // print. Bail out before refreshing the html, otherwise errors might
+        // occur. Don't call the finish func, its expected to be called on
+        // success.
+        return;
+    }
     getEventsAndDialogSettings(
         function getEventsAndDialogSettings_response(settings) {
             document.title = calGetString("calendar", "PrintPreviewWindowTitle", [settings.title]);
 
             let printformatter = Components.classes[settings.layoutCId]
                                            .createInstance(Components.interfaces.calIPrintFormatter);
             let html = "";
             try {
@@ -322,8 +331,21 @@ function printAndClose() {
 
 /**
  * Called when once a date has been selected in the datepicker.
  */
 function onDatePick() {
     calRadioGroupSelectItem("view-field", "custom-range");
     refreshHtml();
 }
+
+/**
+ * Update the disabled state of the controls on the dialog, if not all print
+ * parameters are set (i.e nothing to print).
+ */
+function updatePrintState() {
+    let columns = document.getElementById("columns-for-events-and-tasks");
+    let cboxes = columns.getElementsByTagName("checkbox");
+
+    // If no checkboxes are checked, disable the print button
+    let someChecked = Array.slice(cboxes).some(function(x) x.checked);
+    document.documentElement.getButton("accept").disabled = !someChecked;
+}
--- a/calendar/base/content/dialogs/calendar-print-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-print-dialog.xul
@@ -110,20 +110,20 @@
         </grid>
       </groupbox>
 
       <groupbox id="what-to-print-group">
         <caption label="&calendar.print.range.label;"/>
         <grid id="grid-events-and-tasks">
           <columns id="columns-for-events-and-tasks">
             <column id="column-event">
-              <checkbox id="events" label="&calendar.print.events.label;" checked="true" oncommand="refreshHtml();"/>
+              <checkbox id="events" label="&calendar.print.events.label;" checked="true" oncommand="updatePrintState(); refreshHtml();"/>
             </column>
             <column id="column-tasks">
-              <checkbox id="tasks" label="&calendar.print.tasks.label;" checked="true" oncommand="refreshHtml();"/>
+              <checkbox id="tasks" label="&calendar.print.tasks.label;" checked="true" oncommand="updatePrintState(); refreshHtml();"/>
             </column>
           </columns>
         </grid>
         <radiogroup id="view-field"
                     oncommand="refreshHtml();">
           <radio id="printCurrentViewRadio"
                  label="&calendar.print.currentView2.label;"
                  value="currentView"/>