Bug 1567424 - remove broadcasters from calendar/: remove filterBroadcaster. r=pmorris
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Fri, 06 Sep 2019 13:17:07 +0300
changeset 36742 7d0f5d3a4d33ab882b3c286553a208990bd53a7e
parent 36741 5c976fb4de886d73b0c5f68f9785e4c513f4166f
child 36743 db4c1ff9362849033cde46cabebc545f1ed7005c
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewerspmorris
bugs1567424
Bug 1567424 - remove broadcasters from calendar/: remove filterBroadcaster. r=pmorris
calendar/base/content/calendar-task-view.js
calendar/lightning/content/lightning-menus.xul
calendar/lightning/content/messenger-overlay-sidebar.xul
--- a/calendar/base/content/calendar-task-view.js
+++ b/calendar/base/content/calendar-task-view.js
@@ -344,33 +344,42 @@ var taskDetailsView = {
     event.target.value = "";
   },
 };
 
 /**
  * Updates the currently applied filter for the task view and refreshes the task
  * tree.
  *
- * @param aFilter        The filter name to set.
+ * @param {String} [filter] - The filter name to set.
  */
-function taskViewUpdate(aFilter) {
+function taskViewUpdate(filter) {
   let tree = document.getElementById("calendar-task-tree");
-  let broadcaster = document.getElementById("filterBroadcaster");
-  let oldFilter = broadcaster.getAttribute("value");
-  let filter = oldFilter;
-
-  if (aFilter && !(aFilter instanceof Event)) {
-    filter = aFilter;
+  let oldFilter = tree.getAttribute("filterValue");
+  if (filter && filter != oldFilter) {
+    tree.setAttribute("filterValue", filter);
+    document
+      .querySelectorAll(
+        `menuitem[command="calendar_task_filter_command"][type="radio"],
+         toolbarbutton[command="calendar_task_filter_command"][type="radio"]`
+      )
+      .forEach(item => {
+        if (item.getAttribute("value") == filter) {
+          item.setAttribute("checked", "true");
+        } else {
+          item.removeAttribute("checked");
+        }
+      });
+    let radio = document.querySelector(
+      `radio[command="calendar_task_filter_command"][value="${filter}"]`
+    );
+    if (radio) {
+      radio.radioGroup.selectedItem = radio;
+    }
   }
-
-  if (filter && filter != oldFilter) {
-    broadcaster.setAttribute("value", filter);
-  }
-
-  // update the filter
   tree.updateFilter(filter || "all");
 }
 
 /**
  * Prepares a dialog to send an email to the organizer of the currently selected
  * task in the task view.
  *
  * XXX We already have a function with this name in the event dialog. Either
--- a/calendar/lightning/content/lightning-menus.xul
+++ b/calendar/lightning/content/lightning-menus.xul
@@ -209,19 +209,16 @@
       </menupopup>
     </menu>
     <menu id="ltnTasksMenu"
           observes="calendar_mode_task"
           insertbefore="viewSortMenuSeparator"
           label="&lightning.menu.view.tasks.label;"
           accesskey="&lightning.menu.view.tasks.accesskey;">
       <menupopup id="ltnTasksMenuPopup">
-        <observes element="filterBroadcaster"
-                  attribute="value"
-                  onbroadcast="checkRadioControl(this.parentNode, document.getElementById(this.getAttribute('element')).getAttribute('value'));"/>
         <menuitem id="ltnTasksViewFilterTasks"
                   type="checkbox"
                   label="&calendar.tasks.view.filtertasks.label;"
                   accesskey="&calendar.tasks.view.filtertasks.accesskey;"
                   command="calendar_toggle_filter_command"/>
         <menuseparator id="ltnTasksViewSeparator"/>
         <menuitem id="ltnTasksViewFilterCurrent"
                   name="filtergroup"
@@ -871,19 +868,16 @@
                        observes="calendar_toggle_orientation_command"/>
       </vbox>
     </panelview>
 
     <!-- View / Tasks -->
     <panelview id="appmenu_ltnTasksView"
                class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <observes element="filterBroadcaster"
-                  attribute="value"
-                  onbroadcast="checkRadioControlAppmenu(this.parentNode, document.getElementById(this.getAttribute('element')).getAttribute('value'));"/>
         <toolbarbutton id="appmenu_ltnTasksViewFilterTasks"
                        class="subviewbutton subviewbutton-iconic"
                        type="checkbox"
                        label="&calendar.tasks.view.filtertasks.label;"
                        command="calendar_toggle_filter_command"/>
         <toolbarseparator id="appmenu_ltnTasksViewSeparator"/>
         <toolbarbutton id="appmenu_ltnTasksViewFilterCurrent"
                        class="subviewbutton subviewbutton-iconic"
--- a/calendar/lightning/content/messenger-overlay-sidebar.xul
+++ b/calendar/lightning/content/messenger-overlay-sidebar.xul
@@ -115,19 +115,17 @@
            key="&lightning.keys.event.showTasks.key;"
            modifiers="accel, shift"
            command="new_task_tab"/>
       <key id="todaypanekey" command="calendar_toggle_todaypane_command" keycode="VK_F11"/>
       <key id="calendar-new-event-key" key="&lightning.keys.event.new;" modifiers="accel" command="calendar_new_event_command"/>
       <key id="calendar-new-todo-key" key="&lightning.keys.todo.new;" modifiers="accel" command="calendar_new_todo_command"/>
     </keyset>
 
-    <broadcasterset id="calendar_broadcasters">
-      <broadcaster id="filterBroadcaster" value="all"/>
-    </broadcasterset>
+    <broadcasterset id="calendar_broadcasters"/>
 
     <popupset id="calendar-popupset">
       <menupopup id="list-calendars-context-menu"
                  onpopupshowing="return calendarListSetupContextMenu(event);">
         <menuitem id="list-calendars-context-togglevisible"
                   accesskeyshow="&calendar.context.showcalendar.accesskey;"
                   accesskeyhide="&calendar.context.hidecalendar.accesskey;"
                   oncommand="toggleCalendarVisible(document.getElementById('list-calendars-context-menu').contextCalendar);"/>
@@ -234,19 +232,16 @@
                                label="&calendar.task.filter.title.label;"/>
               <calendar-modevbox id="task-filtertree-pane"
                                  flex="1"
                                  mode="task"
                                  broadcaster="modeBroadcaster"
                                  refcontrol="task-tree-filter-header">
                 <radiogroup id="task-tree-filtergroup" class="task-tree-subpane"
                             persist="value">
-                  <observes element="filterBroadcaster"
-                            attribute="value"
-                            onbroadcast="checkRadioControl(this.parentNode, document.getElementById('filterBroadcaster').getAttribute('value'));"/>
                   <radio id="opt_throughcurrent_filter" label="&calendar.task.filter.current.label;" value="throughcurrent" command="calendar_task_filter_command"/>
                   <radio id="opt_today_filter" label="&calendar.task.filter.today.label;" value="throughtoday" command="calendar_task_filter_command"/>
                   <radio id="opt_next7days_filter" label="&calendar.task.filter.next7days.label;" value="throughsevendays" command="calendar_task_filter_command"/>
                   <radio id="opt_notstarted_filter" label="&calendar.task.filter.notstarted.label;" value="notstarted" command="calendar_task_filter_command"/>
                   <radio id="opt_overdue_filter" label="&calendar.task.filter.overdue.label;" value="overdue" command="calendar_task_filter_command"/>
                   <radio id="opt_completed_filter" label="&calendar.task.filter.completed.label;" value="completed" command="calendar_task_filter_command"/>
                   <radio id="opt_open_filter" label="&calendar.task.filter.open.label;" value="open" command="calendar_task_filter_command"/>
                   <radio id="opt_all_filter" label="&calendar.task.filter.all.label;" value="all" command="calendar_task_filter_command"/>