# HG changeset patch # User Martin Schroeder # Date 1524399397 -7200 # So Apr 22 14:16:37 2018 +0200 # Node ID 3eb0a15e763e95f4e4d31379c32f4c8273b50c49 # Parent 8a5222ed32038f925dc847ccfa4e4359ae1e7fb5 Bug 1399842 - Fix various JS errors in Calendar [ReferenceError: document is not defined]. r=MakeMyDay diff --git a/calendar/base/content/calendar-menus.xml b/calendar/base/content/calendar-menus.xml --- a/calendar/base/content/calendar-menus.xml +++ b/calendar/base/content/calendar-menus.xml @@ -51,17 +51,32 @@ // We are in the Tasks tab. let tasks = getSelectedTasks(); let tasksSelected = (tasks != null) && (tasks.length > 0); if (tasksSelected) { if (tasks.every(task => task[this.mType] == tasks[0][this.mType])) { propertyValue = tasks[0][this.mType]; } } else { - cal.view.applyAttributeToMenuChildren(this, "disabled", !tasksSelected); + let sibling = this.firstChild; + + while (sibling) { + let domObject = sibling; + + if (domObject.hasAttribute("command")) { + let commandName = domObject.getAttribute("command"); + let command = document.getElementById(commandName); + if (command) { + domObject = command; + } + } + + domObject.setAttribute("disabled", false); + sibling = sibling.nextSibling; + } } } if (propertyValue || propertyValue == 0) { let command = document.getElementById("calendar_" + this.mType + "-" + propertyValue + "_command"); if (command) { command.setAttribute("checked", "true"); } } diff --git a/calendar/base/content/calendar-task-tree.js b/calendar/base/content/calendar-task-tree.js --- a/calendar/base/content/calendar-task-tree.js +++ b/calendar/base/content/calendar-task-tree.js @@ -30,16 +30,43 @@ function addCalendarNames(aEvent) { let selIndex = appendCalendarItems(tasks[0], calendarMenuPopup, null, "contextChangeTaskCalendar(event);"); if (tasks.every(task => task.calendar == tasks[0].calendar) && selIndex > -1) { calendarMenuPopup.childNodes[selIndex].setAttribute("checked", "true"); } } } /** + * Applies a value to all children of a menu. If the respective child nodes define + * a command the value is applied to the disabled attribute of the command of the + * child node. + * + * @param aElement The parent node of the elements + * @param aValue The value of the attribute + */ +function applyDisabledAttributeToMenuChildren(aElement, aValue) { + let sibling = aElement.firstChild; + + while (sibling) { + let domObject = sibling; + + if (domObject.hasAttribute("command")) { + let commandName = domObject.getAttribute("command"); + let command = document.getElementById(commandName); + if (command) { + domObject = command; + } + } + + domObject.setAttribute("disabled", aValue); + sibling = sibling.nextSibling; + } +} + +/** * Change the opening context menu for the selected tasks. * * @param aEvent The popupshowing event of the opening menu. */ function changeContextMenuForTask(aEvent) { handleTaskContextMenuStateChange(aEvent); let idnode = document.popupNode.id; @@ -53,34 +80,37 @@ function changeContextMenuForTask(aEvent document.getElementById("task-context-menu-modify-todaypane").hidden = (idnode == "calendar-task-tree"); document.getElementById("task-context-menu-filter-todaypane").hidden = (idnode == "calendar-task-tree"); document.getElementById("task-context-menu-separator-filter").hidden = (idnode == "calendar-task-tree"); let tasksSelected = (items.length > 0); - cal.view.applyAttributeToMenuChildren(aEvent.target, "disabled", !tasksSelected); + applyDisabledAttributeToMenuChildren(aEvent.target, !tasksSelected); + if (calendarController.isCommandEnabled("calendar_new_todo_command") && calendarController.isCommandEnabled("calendar_new_todo_todaypane_command")) { document.getElementById("calendar_new_todo_command").removeAttribute("disabled"); document.getElementById("calendar_new_todo_todaypane_command").removeAttribute("disabled"); } else { document.getElementById("calendar_new_todo_command").setAttribute("disabled", "true"); document.getElementById("calendar_new_todo_todaypane_command").setAttribute("disabled", "true"); } // make sure the "Paste" and "Cut" menu items are enabled goUpdateCommand("cmd_paste"); goUpdateCommand("cmd_cut"); // make sure the filter menu is enabled document.getElementById("task-context-menu-filter-todaypane").removeAttribute("disabled"); - cal.view.applyAttributeToMenuChildren(document.getElementById("task-context-menu-filter-todaypane-popup"), - "disabled", false); + applyDisabledAttributeToMenuChildren( + document.getElementById("task-context-menu-filter-todaypane-popup"), + false + ); changeMenuForTask(aEvent); let menu = document.getElementById("task-context-menu-attendance-menu"); setupAttendanceMenu(menu, items); } /** diff --git a/calendar/base/content/dialogs/calendar-print-dialog.js b/calendar/base/content/dialogs/calendar-print-dialog.js --- a/calendar/base/content/dialogs/calendar-print-dialog.js +++ b/calendar/base/content/dialogs/calendar-print-dialog.js @@ -299,18 +299,30 @@ function printAndClose() { }); return false; // leave open } /** * Called when once a date has been selected in the datepicker. */ function onDatePick() { - cal.view.radioGroupSelectItem("view-field", "custom-range"); - setTimeout(refreshHtml, 0); + 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; + } + } + + if (index && index != 0) { + radioGroup.selectedIndex = index; + setTimeout(refreshHtml, 0); + } } 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"); diff --git a/calendar/base/modules/calUtilsCompat.jsm b/calendar/base/modules/calUtilsCompat.jsm --- a/calendar/base/modules/calUtilsCompat.jsm +++ b/calendar/base/modules/calUtilsCompat.jsm @@ -111,18 +111,17 @@ var migrations = { sortEntryComparer: "sortEntryComparer", getItemSortKey: "getItemSortKey", // compareNative*, compareNumber, sortEntry, sortEntryItem, sortEntryKey and // getSortTypeForSortKey are no longer available. There is a new // cal.unifinder.sortItems though that should do everything necessary. }, view: { isMouseOverBox: "isMouseOverBox", - calRadioGroupSelectItem: "radioGroupSelectItem", - applyAttributeToMenuChildren: "applyAttributeToMenuChildren", + // calRadioGroupSelectItem and applyAttributeToMenuChildren are no longer available. removeChildElementsByAttribute: "removeChildElementsByAttribute", getParentNodeOrThis: "getParentNodeOrThis", getParentNodeOrThisByAttribute: "getParentNodeOrThisByAttribute", formatStringForCSSRule: "formatStringForCSSRule", getCompositeCalendar: "getCompositeCalendar", hashColor: "hashColor", getContrastingTextColor: "getContrastingTextColor" }, diff --git a/calendar/base/modules/utils/calViewUtils.jsm b/calendar/base/modules/utils/calViewUtils.jsm --- a/calendar/base/modules/utils/calViewUtils.jsm +++ b/calendar/base/modules/utils/calViewUtils.jsm @@ -35,65 +35,16 @@ var calview = { let xIsWithin = (mouseX >= boxScreenX) && (mouseX <= (boxScreenX + boxWidth)); let yIsWithin = (mouseY >= boxScreenY) && (mouseY <= (boxScreenY + boxHeight)); return (xIsWithin && yIsWithin); }, /** - * Selects an item with id aItemId in the radio group with id aRadioGroupId - * - * @param aRadioGroupId the id of the radio group which contains the item - * @param aItemId the item to be selected - */ - radioGroupSelectItem: function(aRadioGroupId, aItemId) { - let radioGroup = document.getElementById(aRadioGroupId); - let items = radioGroup.getElementsByTagName("radio"); - let index; - for (let i in items) { - if (items[i].getAttribute("id") == aItemId) { - index = i; - break; - } - } - cal.ASSERT(index && index != 0, "Can't find radioGroup item to select.", true); - radioGroup.selectedIndex = index; - }, - - /** - * Applies a value to all children of a Menu. If the respective childnodes define - * a command the value is applied to the attribute of thecommand of the childnode - * - * @param aElement The parentnode of the elements - * @param aAttributeName The name of the attribute - * @param aValue The value of the attribute - */ - applyAttributeToMenuChildren: function(aElement, aAttributeName, aValue) { - let sibling = aElement.firstChild; - do { - if (sibling) { - let domObject = sibling; - let commandName = null; - if (sibling.hasAttribute("command")) { - commandName = sibling.getAttribute("command"); - } - if (commandName) { - let command = document.getElementById(commandName); - if (command) { - domObject = command; - } - } - domObject.setAttribute(aAttributeName, aValue); - sibling = sibling.nextSibling; - } - } while (sibling); - }, - - /** * Removes those childnodes from a node that contain a specified attribute * and where the value of this attribute matches a passed value * * @param aParentNode The parent node that contains the child nodes in question * @param aAttribute The name of the attribute * @param aAttribute The value of the attribute */ removeChildElementsByAttribute: function(aParentNode, aAttribute, aValue) { diff --git a/calendar/providers/gdata/modules/calUtilsShim.jsm b/calendar/providers/gdata/modules/calUtilsShim.jsm --- a/calendar/providers/gdata/modules/calUtilsShim.jsm +++ b/calendar/providers/gdata/modules/calUtilsShim.jsm @@ -55,18 +55,16 @@ if (!cal.item) { findWindow: (...args) => cal.findItemWindow(...args), setToAllDay: (...args) => cal.setItemToAllDay(...args) }; } if (!cal.view || !cal.view.hashColor) { cal.view = Object.assign(cal.view || {}, { isMouseOverBox: (...args) => cal.isMouseOverBox(...args), - radioGroupSelectItem: (...args) => cal.calRadioGroupSelectItem(...args), - applyAttributeToMenuChildren: (...args) => cal.applyAttributeToMenuChildren(...args), removeChildElementsByAttribute: (...args) => cal.removeChildElementsByAttribute(...args), getParentNodeOrThis: (...args) => cal.getParentNodeOrThis(...args), getParentNodeOrThisByAttribute: (...args) => cal.getParentNodeOrThisByAttribute(...args), formatStringForCSSRule: (...args) => cal.formatStringForCSSRule(...args), getCompositeCalendar: (...args) => cal.getCompositeCalendar(...args), hashColor: (...args) => cal.hashColor(...args), getContrastingTextColor: (...args) => cal.getContrastingTextColor(...args), /* cal.view.compareItems stays the same, just a different import */