Bug 1541789 - Follow-up: Tidy up dialogaccept and dialogcancel listeners in calendar/. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Sun, 14 Apr 2019 22:10:04 +1200
changeset 26345 ad2d84d80a1ee61bd4ba33a33715a9859236a388
parent 26344 30a7914d1c644a567f1956c6667295183accbb42
child 26346 dd798dde8956500e6d0cadb22875a28fcd891c1b
push id15794
push usermozilla@jorgk.com
push dateMon, 15 Apr 2019 13:56:46 +0000
treeherdercomm-central@ad2d84d80a1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1541789
Bug 1541789 - Follow-up: Tidy up dialogaccept and dialogcancel listeners in calendar/. r=philipp
calendar/base/content/dialogs/calendar-event-dialog-attendees.js
calendar/base/content/dialogs/calendar-event-dialog-recurrence.js
calendar/base/content/dialogs/calendar-event-dialog-reminder.js
calendar/base/content/dialogs/calendar-event-dialog-timezone.js
calendar/base/content/dialogs/calendar-invitations-dialog.js
calendar/base/content/dialogs/calendar-print-dialog.js
calendar/base/content/dialogs/calendar-properties-dialog.js
calendar/base/content/dialogs/calendar-providerUninstall-dialog.js
calendar/base/content/dialogs/calendar-subscriptions-dialog.js
calendar/base/content/dialogs/calendar-summary-dialog.js
calendar/base/content/dialogs/chooseCalendarDialog.js
calendar/base/content/preferences/editCategory.js
calendar/lightning/content/lightning-item-panel.js
calendar/providers/gdata/content/gdata-migration.js
calendar/resources/content/publishDialog.js
--- a/calendar/base/content/dialogs/calendar-event-dialog-attendees.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-attendees.js
@@ -21,18 +21,16 @@ var gEndHour = 24;
 var gIsReadOnly = false;
 var gIsInvitation = false;
 var gIgnoreUpdate = false;
 var gDisplayTimezone = true;
 var gUndoStack = [];
 var gForce24Hours = false;
 var gZoomFactor = 100;
 
-document.addEventListener("dialogaccept", onAccept);
-
 /**
  * Sets up the attendee dialog
  */
 function onLoad() {
     // set calendar-event-freebusy-timebar date and time properties
     setFreebusyTimebarTime();
 
     // set up some calendar-event-freebusy-timebar properties
@@ -117,27 +115,25 @@ function onLoad() {
 
     opener.setCursor("auto");
     self.focus();
 }
 
 /**
  * This function should be called when the accept button was pressed on the
  * attendee dialog. Calls the accept function specified in the window arguments.
- *
- * @return      Returns true, if the dialog should be closed.
  */
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     let attendees = document.getElementById("attendees-list");
     window.arguments[0].onOk(
         attendees.attendees,
         attendees.organizer,
         gStartDate.getInTimezone(gStartTimezone),
         gEndDate.getInTimezone(gEndTimezone));
-}
+});
 
 /**
  * Function called when zoom buttons (+/-) are clicked.
  *
  * @param aZoomOut      true -> zoom out; false -> zoom in.
  */
 function zoomWithButtons(aZoomOut) {
     let zoom = document.getElementById("zoom-menulist");
--- a/calendar/base/content/dialogs/calendar-event-dialog-recurrence.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-recurrence.js
@@ -10,19 +10,16 @@ var { splitRecurrenceRules } = ChromeUti
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var gIsReadOnly = false;
 var gStartTime = null;
 var gEndTime = null;
 var gUntilDate = null;
 
-document.addEventListener("dialogaccept", onAccept);
-document.addEventListener("dialogcancel", onCancel);
-
 /**
  * Object wrapping the methods and properties of recurrence-preview binding.
  */
 const RecurrencePreview = {
     /**
      * Initializes some properties and adds event listener to the #recurrence-preview node.
      */
     init() {
@@ -756,38 +753,34 @@ function onSave(item) {
     }
 
     recurrenceInfo.insertRecurrenceItemAt(recRule, 0);
     return recurrenceInfo;
 }
 
 /**
  * Handler function to be called when the accept button is pressed.
- *
- * @return      Returns true if the window should be closed
  */
-function onAccept(event) {
+document.addEventListener("dialogaccept", (event) => {
     let args = window.arguments[0];
     let item = args.calendarEvent;
     args.onOk(onSave(item));
     // Don't close the dialog if a warning must be showed.
     if (checkUntilDate.warning) {
         event.preventDefault();
     }
-}
+});
 
 /**
  * Handler function to be called when the Cancel button is pressed.
- *
- * @return      Returns true if the window should be closed
  */
-function onCancel() {
+document.addEventListener("dialogcancel", () => {
     // Don't show any warning if the dialog must be closed.
     checkUntilDate.warning = false;
-}
+});
 
 /**
  * Handler function called when the calendar is changed (also for initial
  * setup).
  *
  * XXX we don't change the calendar in this dialog, this function should be
  * consolidated or renamed.
  *
--- a/calendar/base/content/dialogs/calendar-event-dialog-reminder.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-reminder.js
@@ -9,19 +9,16 @@
 var { PluralForm } = ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
 var allowedActionsMap = {};
 var suppressListUpdate = false;
 
-document.addEventListener("dialogaccept", onAccept);
-document.addEventListener("dialogcancel", onCancel);
-
 /**
  * Sets up the reminder dialog.
  */
 function onLoad() {
     let calendar = window.arguments[0].calendar;
 
     // Make sure the origin menulist uses the right labels, depending on if the
     // dialog is showing an event or task.
@@ -451,27 +448,25 @@ function onRemoveReminder() {
     setElementValue("reminder-remove-button",
                     listbox.childNodes.length < 1 && "true",
                     "disabled");
     setupMaxReminders();
 }
 
 /**
  * Handler function to be called when the accept button is pressed.
- *
- * @return      Returns true if the window should be closed
  */
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     let listbox = document.getElementById("reminder-listbox");
     let reminders = Array.from(listbox.childNodes).map(node => node.reminder);
     if (window.arguments[0].onOk) {
         window.arguments[0].onOk(reminders);
     }
-}
+});
 
 /**
  * Handler function to be called when the cancel button is pressed.
  */
-function onCancel() {
+document.addEventListener("dialogcancel", () => {
     if (window.arguments[0].onCancel) {
         window.arguments[0].onCancel();
     }
-}
+});
--- a/calendar/base/content/dialogs/calendar-event-dialog-timezone.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-timezone.js
@@ -3,18 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* exported onLoad */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
-document.addEventListener("dialogaccept", onAccept);
-
 /**
  * Sets up the timezone dialog from the window arguments, also setting up all
  * dialog controls from the window's dates.
  */
 function onLoad() {
     let args = window.arguments[0];
     window.time = args.time;
     window.onAcceptCallback = args.onOk;
@@ -114,21 +112,20 @@ function updateTimezone() {
         let standard = timezone.icalComponent.getFirstSubcomponent("STANDARD");
         // any reason why valueAsIcalString is used instead of plain value? xxx todo: ask mickey
         standardTZOffset = standard.getFirstProperty("TZOFFSETTO").valueAsIcalString;
     }
 
     let image = document.getElementById("highlighter");
     image.setAttribute("tzid", standardTZOffset);
 }
+
 /**
  * Handler function to be called when the accept button is pressed.
- *
- * @return      Returns true if the window should be closed
  */
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     let menulist = document.getElementById("timezone-menulist");
     let menuitem = menulist.selectedItem;
     let timezoneString = menuitem.getAttribute("value");
     let timezone = window.tzProvider.getTimezone(timezoneString);
     let datetime = window.time.getInTimezone(timezone);
     window.onAcceptCallback(datetime);
-}
+});
--- a/calendar/base/content/dialogs/calendar-invitations-dialog.js
+++ b/calendar/base/content/dialogs/calendar-invitations-dialog.js
@@ -3,19 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* exported onLoad, onUnload */
 
 /* globals invitationsText */// From calendar-invitations-dialog.xul.
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
-document.addEventListener("dialogaccept", onAccept);
-document.addEventListener("dialogcancel", onCancel);
-
 /**
  * Sets up the invitations dialog from the window arguments, retrieves the
  * invitations from the invitations manager.
  */
 function onLoad() {
     let operationListener = {
         QueryInterface: ChromeUtils.generateQI([Ci.calIOperationListener]),
         onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {
@@ -61,34 +58,32 @@ function onLoad() {
  */
 function onUnload() {
     let args = window.arguments[0];
     args.requestManager.cancelPendingRequests();
 }
 
 /**
  * Handler function to be called when the accept button is pressed.
- *
- * @return      Returns true if the window should be closed
  */
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     let args = window.arguments[0];
     fillJobQueue(args.queue);
     args.invitationsManager.processJobQueue(args.queue, args.finishedCallBack);
-}
+});
 
 /**
  * Handler function to be called when the cancel button is pressed.
  */
-function onCancel() {
+document.addEventListener("dialogcancel", () => {
     let args = window.arguments[0];
     if (args.finishedCallBack) {
         args.finishedCallBack();
     }
-}
+});
 
 /**
  * Fills the job queue from the invitations-listbox's items. The job queue
  * contains objects for all items that have a modified participation status.
  *
  * @param queue     The queue to fill.
  */
 function fillJobQueue(queue) {
--- a/calendar/base/content/dialogs/calendar-print-dialog.js
+++ b/calendar/base/content/dialogs/calendar-print-dialog.js
@@ -1,24 +1,22 @@
 /* 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, printAndClose, onDatePick */
+/* exported loadCalendarPrintDialog, onDatePick */
 
 /* 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 = "";
 
-document.addEventListener("dialogaccept", printAndClose);
-
 /**
  * Gets the calendar view from the opening window
  */
 function getCalendarView() {
     let theView = window.opener.currentView();
     if (!theView.startDay) {
         theView = null;
     }
@@ -242,17 +240,17 @@ function refreshHtml(finishFunc) {
         }
     }
 );
 }
 
 /**
  * Prints the document and then closes the window
  */
-function printAndClose(event) {
+document.addEventListener("dialogaccept", (event) => {
     refreshHtml(() => {
         let printSettings = PrintUtils.getPrintSettings();
         // Evicts "about:blank" header
         printSettings.docURL = " ";
 
         // we don't do anything with statusFeedback, msgPrintEngine requires it
         let statusFeedback = Cc["@mozilla.org/messenger/statusfeedback;1"]
                                  .createInstance();
@@ -279,17 +277,17 @@ function printAndClose(event) {
                             .getService(Ci.nsIPrintSettingsService);
             PSSVC.savePrintSettingsToPrefs(printSettings, true,
                                            printSettings.kInitSaveAll);
             PSSVC.savePrintSettingsToPrefs(printSettings, false,
                                            printSettings.kInitSavePrinterName);
         }
     });
     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;
--- a/calendar/base/content/dialogs/calendar-properties-dialog.js
+++ b/calendar/base/content/dialogs/calendar-properties-dialog.js
@@ -1,22 +1,19 @@
 /* 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 onLoad, onAcceptDialog, unsubscribeCalendar */
+/* exported onLoad */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { PluralForm } = ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
 
-document.addEventListener("dialogextra1", unsubscribeCalendar);
-document.addEventListener("dialogaccept", onAcceptDialog);
-
 /**
  * The calendar to modify, is retrieved from window.arguments[0].calendar
  */
 var gCalendar;
 
 /**
  * This function gets called when the calendar properties dialog gets opened. To
  * open the window, use an object as argument. The object needs a 'calendar'
@@ -70,18 +67,16 @@ function onLoad() {
         document.getElementById("calendar-name").focus();
     }
 
     sizeToContent();
 }
 
 /**
  * Called when the dialog is accepted, to save settings.
- *
- * @return      Returns true if the dialog should be closed.
  */
 function onAcceptDialog() {
     // Save calendar name
     gCalendar.name = document.getElementById("calendar-name").value;
 
     // Save calendar color
     gCalendar.setProperty("color", document.getElementById("calendar-color").value);
 
@@ -104,38 +99,39 @@ function onAcceptDialog() {
     }
 
     if (!gCalendar.getProperty("force-disabled")) {
         // Save disabled option (should do this last), remove auto-enabled
         gCalendar.setProperty("disabled", !document.getElementById("calendar-enabled-checkbox").checked);
         gCalendar.deleteProperty("auto-enabled");
     }
 }
+document.addEventListener("dialogaccept", onAcceptDialog);
 
 /**
  * When the calendar is disabled, we need to disable a number of other elements
  */
 function setupEnabledCheckbox() {
     let isEnabled = document.getElementById("calendar-enabled-checkbox").checked;
     let els = document.getElementsByAttribute("disable-with-calendar", "true");
     for (let i = 0; i < els.length; i++) {
         els[i].disabled = !isEnabled || (els[i].getAttribute("disable-capability") == "true");
     }
 }
 
 /**
  * Called to unsubscribe from a calendar. The button for this function is not
  * shown unless the provider for the calendar is missing (i.e force-disabled)
  */
-function unsubscribeCalendar() {
+document.addEventListener("dialogextra1", () => {
     let calmgr = cal.getCalendarManager();
 
     calmgr.unregisterCalendar(gCalendar);
     window.close();
-}
+});
 
 function initRefreshInterval() {
     function createMenuItem(minutes) {
         let menuitem = document.createXULElement("menuitem");
         menuitem.setAttribute("value", minutes);
 
         let everyMinuteString = cal.l10n.getCalString("calendarPropertiesEveryMinute");
         let label = PluralForm.get(minutes, everyMinuteString).replace("#1", minutes);
--- a/calendar/base/content/dialogs/calendar-providerUninstall-dialog.js
+++ b/calendar/base/content/dialogs/calendar-providerUninstall-dialog.js
@@ -1,37 +1,34 @@
 /* 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 onLoad */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
-document.addEventListener("dialogaccept", onAccept);
-document.addEventListener("dialogcancel", onCancel);
-
 function onLoad() {
     let extension = window.arguments[0].extension;
     document.getElementById("provider-name-label").value = extension.name;
 
     let calendars = cal.getCalendarManager().getCalendars({})
                        .filter(x => x.providerID == extension.id);
 
     document.getElementById("calendar-list-tree").calendars = calendars;
 }
 
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     // Tell our caller that the extension should be uninstalled.
     let args = window.arguments[0];
     args.shouldUninstall = true;
 
     // Unsubscribe from all selected calendars
     let calendarList = document.getElementById("calendar-list-tree");
     let calendars = calendarList.selectedCalendars || [];
     let calMgr = cal.getCalendarManager();
     calendars.forEach(calMgr.unregisterCalendar, calMgr);
-}
+});
 
-function onCancel() {
+document.addEventListener("dialogcancel", () => {
     let args = window.arguments[0];
     args.shouldUninstall = false;
-}
+});
--- a/calendar/base/content/dialogs/calendar-subscriptions-dialog.js
+++ b/calendar/base/content/dialogs/calendar-subscriptions-dialog.js
@@ -1,18 +1,16 @@
 /* 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 onLoad, onUnload, onKeyPress, onTextBoxKeyPress, onSubscribe, onUnsubscribe */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
-document.addEventListener("dialogaccept", onAccept);
-
 /**
  * Cancels any pending search operations.
  */
 var gCurrentSearchOperation = null;
 function cancelPendingSearchOperation() {
     if (gCurrentSearchOperation && gCurrentSearchOperation.isPending) {
         gCurrentSearchOperation.cancel(Ci.calIErrors.OPERATION_CANCELLED);
     }
@@ -61,35 +59,33 @@ function onTextBoxKeyPress(event) {
             event.stopPropagation();
             event.preventDefault();
             break;
     }
 }
 
 /**
  * Handler function to be called when the accept button is pressed.
- *
- * @return      Returns true if the window should be closed
  */
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     let richListBox = document.getElementById("subscriptions-listbox");
     let rowCount = richListBox.getRowCount();
     for (let i = 0; i < rowCount; i++) {
         let richListItem = richListBox.getItemAtIndex(i);
         let checked = richListItem.checked;
         if (checked != richListItem.subscribed) {
             let calendar = richListItem.calendar;
             if (checked) {
                 cal.getCalendarManager().registerCalendar(calendar);
             } else {
                 cal.getCalendarManager().unregisterCalendar(calendar);
             }
         }
     }
-}
+});
 
 /**
  * Performs the search for subscriptions, canceling any pending searches.
  */
 function onSearch() {
     cancelPendingSearchOperation();
 
     let richListBox = document.getElementById("subscriptions-listbox");
--- a/calendar/base/content/dialogs/calendar-summary-dialog.js
+++ b/calendar/base/content/dialogs/calendar-summary-dialog.js
@@ -7,19 +7,16 @@
  */
 
 /* import-globals-from ../../src/calApplicationUtils.js */
 /* import-globals-from calendar-dialog-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { recurrenceRule2String } = ChromeUtils.import("resource://calendar/modules/calRecurrenceUtils.jsm");
 
-document.addEventListener("dialogaccept", onAccept);
-document.addEventListener("dialogcancel", onCancel);
-
 /**
  * Sets up the summary dialog, setting all needed fields on the dialog from the
  * item received in the window arguments.
  */
 function onLoad() {
     let args = window.arguments[0];
     let item = args.calendarEvent;
     item = item.clone(); // use an own copy of the passed item
@@ -263,41 +260,41 @@ function onUnload() {
     if (typeof window.ToolbarIconColor !== "undefined") {
         window.ToolbarIconColor.uninit();
     }
 }
 
 /**
  * Saves any changed information to the item.
  */
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     dispose();
     if (window.readOnly) {
         return;
     }
     // let's make sure we have a response mode defined
     let resp = window.responseMode || "USER";
     let respMode = { responseMode: Ci.calIItipItem[resp] };
 
     let args = window.arguments[0];
     let oldItem = args.calendarEvent;
     let newItem = window.calendarItem;
     let calendar = newItem.calendar;
     saveReminder(newItem);
     adaptScheduleAgent(newItem);
     args.onOk(newItem, calendar, oldItem, null, respMode);
     window.calendarItem = newItem;
-}
+});
 
 /**
  * Called when closing the dialog and any changes should be thrown away.
  */
-function onCancel() {
+document.addEventListener("dialogcancel", () => {
     dispose();
-}
+});
 
 /**
  * Updates the user's partstat, sends a notification if requested and closes the
  * dialog
  *
  * @param {string}  aResponse  a literal of one of the response modes defined
  *                               in calIItipItem (like 'NONE')
  * @param {string}  aPartStat  (optional) a partstat as per RfC5545
--- a/calendar/base/content/dialogs/chooseCalendarDialog.js
+++ b/calendar/base/content/dialogs/chooseCalendarDialog.js
@@ -1,21 +1,18 @@
 /* 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 loadCalendars, doOK, doExtra1 */
+/* exported loadCalendars */
 
 /* import-globals-from ../calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
-document.addEventListener("dialogaccept", doOK);
-document.addEventListener("dialogextra1", doExtra1);
-
 function loadCalendars() {
     const calendarManager = Cc["@mozilla.org/calendar/manager;1"]
                               .getService(Ci.calICalendarManager);
     let listbox = document.getElementById("calendar-list");
     let composite = cal.view.getCompositeCalendar(window.opener);
     let selectedIndex = 0;
     let calendars;
 
@@ -77,18 +74,18 @@ function loadCalendars() {
     } else {
         // If there are no calendars, then disable the accept button
         document.documentElement.getButton("accept").setAttribute("disabled", "true");
     }
 
     window.sizeToContent();
 }
 
-function doOK() {
+document.addEventListener("dialogaccept", () => {
     let listbox = document.getElementById("calendar-list");
     window.arguments[0].onOk(listbox.selectedItem.calendar);
-}
+});
 
-function doExtra1() {
+document.addEventListener("dialogextra1", () => {
     let listbox = document.getElementById("calendar-list");
     window.arguments[0].onExtra1(listbox.selectedItem.calendar);
     window.close();
-}
+});
--- a/calendar/base/content/preferences/editCategory.js
+++ b/calendar/base/content/preferences/editCategory.js
@@ -1,18 +1,16 @@
 /* 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 editCategoryLoad, doOK, categoryNameChanged, clickColor, delay */
+/* exported editCategoryLoad, categoryNameChanged, clickColor, delay */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
-document.addEventListener("dialogaccept", doOK);
-
 // Global variable, set to true if the user has picked a custom color.
 var customColorSelected = false;
 
 /**
  * Load Handler, called when the edit category dialog is loaded
  */
 function editCategoryLoad() {
     let winArg = window.arguments[0];
@@ -26,24 +24,24 @@ function editCategoryLoad() {
 
     toggleColor();
 }
 
 /**
  * Handler function to be called when the category dialog is accepted and
  * the opener should further process the selected name and color
  */
-function doOK() {
+document.addEventListener("dialogaccept", () => {
     let color = document.getElementById("useColor").checked
                     ? document.getElementById("categoryColor").value
                     : null;
 
     let categoryName = document.getElementById("categoryName").value;
     window.opener.gCategoriesPane.saveCategory(categoryName, color);
-}
+});
 
 /**
  * Handler function to be called when the category name changed
  */
 function categoryNameChanged() {
     let newValue = document.getElementById("categoryName").value;
 
     // The user removed the category name, assign the color automatically again.
--- a/calendar/lightning/content/lightning-item-panel.js
+++ b/calendar/lightning/content/lightning-item-panel.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 onLoadLightningItemPanel, onAccept, onCancel, onCommandSave,
+/* exported onLoadLightningItemPanel, onCancel, onCommandSave,
  *          onCommandDeleteItem, editAttendees, editPrivacy, editPriority,
  *          editStatus, editShowTimeAs, updateShowTimeAs, editToDoStatus,
  *          postponeTask, toggleTimezoneLinks, toggleLink, attachURL,
  *          onCommandViewToolbar, onCommandCustomize, attachFileByAccountKey,
  *          onUnloadLightningItemPanel, openNewEvent, openNewTask,
  *          openNewMessage, openNewCardDialog
  */
 
@@ -57,19 +57,16 @@ if (!gTabmail) {
     /**
      * Update menu items that depend on clipboard contents.
      */
     window.goUpdatePasteMenuItems = () => {
         goUpdateCommand("cmd_paste");
     };
 }
 
-document.addEventListener("dialogaccept", onAccept);
-document.addEventListener("dialogcancel", onCancel);
-
 // Stores the ids of the iframes of currently open event/task tabs, used
 // when window is closed to prompt for saving changes.
 var gItemTabIds = [];
 var gItemTabIdsCopy;
 
 // gConfig is used when switching tabs to restore the state of
 // toolbar, statusbar, and menubar for the current tab.
 var gConfig = {
@@ -372,23 +369,33 @@ function initializeItemMenu(aLabel, aAcc
     let menuItem = document.getElementById("item-menu");
     menuItem.setAttribute("label", aLabel);
     menuItem.setAttribute("accesskey", aAccessKey);
 }
 
 /**
  * Handler for when dialog is accepted.
  */
-function onAccept() {
+document.addEventListener("dialogaccept", () => {
     sendMessage({ command: "onAccept" });
     return false;
-}
+});
 
 /**
- * Handler for when dialog is canceled.
+ * Handler for when dialog is cancelled. (calendar.item.editInTab = false)
+ */
+document.addEventListener("dialogcancel", (event) => {
+    sendMessage({ command: "onCancel" });
+    // We prevent closing of a window until we
+    // can ask the user about saving any unsaved changes.
+    event.preventDefault();
+});
+
+/**
+ * Handler for when tab is cancelled. (calendar.item.editInTab = true)
  *
  * @param {string} aIframeId  The id of the iframe
  */
 function onCancel(aIframeId) {
     sendMessage({ command: "onCancel", iframeId: aIframeId }, aIframeId);
     // We return false to prevent closing of a window until we
     // can ask the user about saving any unsaved changes.
     return false;
--- a/calendar/providers/gdata/content/gdata-migration.js
+++ b/calendar/providers/gdata/content/gdata-migration.js
@@ -2,22 +2,20 @@
  * 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/. */
 
 /* import-globals-from ../../../base/content/calendar-ui-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-document.addEventListener("dialogaccept", migrateSelectedCalendars);
-
 /**
  * Migrate the calendar selected in the wizard from ics to gdata.
  */
-function migrateSelectedCalendars() {
+document.addEventListener("dialogaccept", () => {
     let listbox = document.getElementById("calendars-listbox");
     let calmgr = cal.getCalendarManager();
 
     for (let i = 0; i < listbox.childNodes.length; i++) {
         let item = listbox.childNodes[i];
         if (item.checked) {
             // Migrate the calendar to a gdata calendar
             let newCal = calmgr.createCalendar("gdata", item.calendar.uri);
@@ -40,17 +38,17 @@ function migrateSelectedCalendars() {
 
             calmgr.registerCalendar(newCal);
         }
     }
 
     // Only bring up the dialog on the next startup if the user wants us to.
     Services.prefs.setBoolPref("calendar.google.migrate",
                                document.getElementById("showagain-checkbox").checked);
-}
+});
 
 /**
  * Get all calendars that are ics and point to a google calendar
  *
  * @return An array of calendars that are migratable
  */
 function getMigratableCalendars() {
     function isMigratable(calendar) {
--- a/calendar/resources/content/publishDialog.js
+++ b/calendar/resources/content/publishDialog.js
@@ -4,18 +4,16 @@
 
 /* exported loadCalendarPublishDialog, closeDialog */
 
 /* globals publishButtonLabel, closeButtonLabel */// From publishDialog.xul
 
 var gOnOkFunction;   // function to be called when user clicks OK
 var gPublishObject;
 
-document.addEventListener("dialogaccept", onOKCommand);
-
 /**
 *   Called when the dialog is loaded.
 */
 function loadCalendarPublishDialog() {
     // Get arguments, see description at top of file
 
     let args = window.arguments[0];
 
@@ -44,16 +42,17 @@ function onOKCommand(event) {
     gPublishObject.remotePath = document.getElementById("publish-remotePath-textbox").value;
 
     // call caller's on OK function
     gOnOkFunction(gPublishObject, progressDialog);
     document.getElementById("calendar-publishwindow").getButton("accept").setAttribute("label", closeButtonLabel);
     document.removeEventListener("dialogaccept", onOKCommand);
     event.preventDefault();
 }
+document.addEventListener("dialogaccept", onOKCommand);
 
 function checkURLField() {
     if (document.getElementById("publish-remotePath-textbox").value.length == 0) {
         document.getElementById("calendar-publishwindow").getButton("accept").setAttribute("disabled", "true");
     } else {
         document.getElementById("calendar-publishwindow").getButton("accept").removeAttribute("disabled");
     }
 }