Bug 1561483 - Fix bad initialisation of calendar print dialog. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 26 Jun 2019 15:07:05 +1200
changeset 35997 e0edf02808494b9f1f3f36d18097c7adc2666a60
parent 35996 06efd8b78dc6f9e04db51f5b0a6b25a5869be81d
child 35998 796d020bab06cde6baf0882a39f90d2560ebae2a
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersphilipp
bugs1561483
Bug 1561483 - Fix bad initialisation of calendar print dialog. r=philipp
calendar/base/content/dialogs/calendar-print-dialog.js
calendar/base/content/dialogs/calendar-print-dialog.xul
calendar/resources/content/datetimepickers/datetimepickers.js
--- a/calendar/base/content/dialogs/calendar-print-dialog.js
+++ b/calendar/base/content/dialogs/calendar-print-dialog.js
@@ -1,13 +1,13 @@
 /* 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/. */
 
-/* exported loadCalendarPrintDialog, onDatePick */
+/* exported loadCalendarPrintDialog */
 
 /* import-globals-from ../../../../../toolkit/components/printing/content/printUtils.js */
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
 var printContent = "";
@@ -53,16 +53,19 @@ function loadCalendarPrintDialog() {
     layoutList.selectedIndex = 0;
 
     opener.setCursor("auto");
 
     eventsAndTasksOptions("tasks");
 
     refreshHtml();
 
+    document.getElementById("start-date-picker").addEventListener("change", onDatePick);
+    document.getElementById("end-date-picker").addEventListener("change", onDatePick);
+
     self.focus();
 }
 
 /**
  * Retrieves a settings object containing info on what to print. The
  * receiverFunc will be called with the settings object containing various print
  * settings.
  *
@@ -233,18 +236,17 @@ function refreshHtml(finishFunc) {
         }
 
         printContent = "data:text/html," + encodeURIComponent(printContent);
         document.getElementById("content").src = printContent;
 
         if (finishFunc) {
             finishFunc();
         }
-    }
-);
+    });
 }
 
 /**
  * Prints the document and then closes the window
  */
 document.addEventListener("dialogaccept", (event) => {
     refreshHtml(() => {
         let printSettings = PrintUtils.getPrintSettings();
@@ -284,29 +286,19 @@ document.addEventListener("dialogaccept"
     event.preventDefault(); // leave open
 });
 
 /**
  * Called when once a date has been selected in the datepicker.
  */
 function onDatePick() {
     let radioGroup = document.getElementById("view-field");
-    let items = radioGroup.getElementsByTagName("radio");
-    let index;
-    for (let i in items) {
-        if (items[i].getAttribute("id") == "custom-range") {
-            index = i;
-            break;
-        }
-    }
+    radioGroup.value = "custom";
 
-    if (index && index != 0) {
-        radioGroup.selectedIndex = index;
-        setTimeout(refreshHtml, 0);
-    }
+    setTimeout(refreshHtml);
 }
 
 function eventsAndTasksOptions(targetId) {
     let checkbox = document.getElementById(targetId);
     let checked = checkbox.getAttribute("checked") == "true";
     // Workaround to make the checkbox persistent (bug 15232).
     checkbox.setAttribute("checked", checked ? "true" : "false");
 
--- a/calendar/base/content/dialogs/calendar-print-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-print-dialog.xul
@@ -101,24 +101,22 @@
               <column/>
               <column flex="1"/>
             </columns>
 
             <rows>
               <row align="center">
                 <label control="start-date-picker"
                        value="&calendar.print.from.label;"/>
-                <datepicker id="start-date-picker"
-                            onchange="onDatePick();"/>
+                <datepicker id="start-date-picker"/>
               </row>
               <row align="center">
                 <label control="end-date-picker"
                        value="&calendar.print.to.label;"/>
-                <datepicker id="end-date-picker"
-                            onchange="onDatePick();"/>
+                <datepicker id="end-date-picker"/>
               </row>
             </rows>
           </grid>
         </radiogroup>
       </groupbox>
       <groupbox id="optionsGroup" label="&calendar.print.optionsGroup.label;">
         <hbox class="groupbox-title">
           <label class="header">&calendar.print.optionsGroup.label;</label>
--- a/calendar/resources/content/datetimepickers/datetimepickers.js
+++ b/calendar/resources/content/datetimepickers/datetimepickers.js
@@ -1132,19 +1132,21 @@
         }
     }
 
     initDateFormat();
     initTimeFormat();
     customElements.define("timepicker-minute", MozTimepickerMinute);
     customElements.define("timepicker-hour", MozTimepickerHour);
     customElements.define("timepicker-grids", MozTimepickerGrids);
-    customElements.define("datepicker", CalendarDatePicker);
-    customElements.define("timepicker", CalendarTimePicker);
-    customElements.define("datetimepicker", CalendarDateTimePicker);
+    customElements.whenDefined("menulist-editable").then(() => {
+        customElements.define("datepicker", CalendarDatePicker);
+        customElements.define("timepicker", CalendarTimePicker);
+        customElements.define("datetimepicker", CalendarDateTimePicker);
+    });
 
     /**
      * Parameter aValue may be a date or a date time. Dates are
      * read according to locale/OS setting (d-m-y or m-d-y or ...).
      * (see initDateFormat). Uses parseTime() for times.
      */
     function parseDateTime(aValue) {
         let tempDate = null;