Bug 1580445 - move calendar-unifinder-todo.js functioality into today-pane.js which is the only consumer. r=Fallen
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Fri, 13 Sep 2019 13:26:24 +0300
changeset 36799 9de382d47166dba89f86f8d32a324cd14c309a7e
parent 36798 41554a073241a3888cedd0f92dd65011af924cc3
child 36800 40347deab546ceb07dcfb37c7c246dfd9fbf05a1
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersFallen
bugs1580445
Bug 1580445 - move calendar-unifinder-todo.js functioality into today-pane.js which is the only consumer. r=Fallen
calendar/base/content/calendar-chrome-startup.js
calendar/base/content/calendar-unifinder-todo.js
calendar/base/content/today-pane.js
calendar/base/content/today-pane.xul
calendar/base/jar.mn
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -1,16 +1,15 @@
 /* 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/. */
 
 /* import-globals-from ../../lightning/content/messenger-overlay-sidebar.js */
 /* import-globals-from calendar-common-sets.js */
 /* import-globals-from calendar-management.js */
-/* import-globals-from calendar-unifinder-todo.js */
 /* import-globals-from calendar-ui-utils.js */
 /* import-globals-from calendar-views-utils.js */
 /* globals PanelUI */
 
 var { fixIterator } = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { AppConstants } = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
deleted file mode 100644
--- a/calendar/base/content/calendar-unifinder-todo.js
+++ /dev/null
@@ -1,59 +0,0 @@
-/* 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 prepareCalendarToDoUnifinder */
-
-/* import-globals-from calendar-views-utils.js */
-
-// TODO: just include these in today-pane.js
-
-/**
- * Called when the window is loaded to set up the unifinder-todo.
- */
-function prepareCalendarToDoUnifinder() {
-  // add listener to update the date filters
-  getViewDeck().addEventListener("dayselect", event => {
-    updateCalendarToDoUnifinder();
-  });
-
-  updateCalendarToDoUnifinder();
-}
-
-/**
- * Updates the applied filter and show completed view of the unifinder todo.
- *
- * @param {String} [filter] - The filter name to set.
- */
-function updateCalendarToDoUnifinder(filter) {
-  let tree = document.getElementById("unifinder-todo-tree");
-
-  // Set up hiding completed tasks for the unifinder-todo tree
-  filter = filter || tree.getAttribute("filterValue") || "throughcurrent";
-  tree.setAttribute("filterValue", filter);
-
-  document
-    .querySelectorAll('menuitem[command="calendar_task_filter_todaypane_command"][type="radio"]')
-    .forEach(item => {
-      if (item.getAttribute("value") == filter) {
-        item.setAttribute("checked", "true");
-      } else {
-        item.removeAttribute("checked");
-      }
-    });
-
-  let showCompleted = document.getElementById("show-completed-checkbox").checked;
-  if (!showCompleted) {
-    let filterProps = tree.mFilter.getDefinedFilterProperties(filter);
-    if (filterProps) {
-      filterProps.status =
-        (filterProps.status || filterProps.FILTER_STATUS_ALL) &
-        (filterProps.FILTER_STATUS_INCOMPLETE | filterProps.FILTER_STATUS_IN_PROGRESS);
-      filter = filterProps;
-    }
-  }
-
-  // update the filter
-  tree.showCompleted = showCompleted;
-  tree.updateFilter(filter);
-}
--- a/calendar/base/content/today-pane.js
+++ b/calendar/base/content/today-pane.js
@@ -1,16 +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/. */
 
 /* import-globals-from ../../lightning/content/messenger-overlay-sidebar.js */
 /* import-globals-from agenda-listbox-utils.js */
 /* import-globals-from calendar-chrome-startup.js */
-/* import-globals-from calendar-unifinder-todo.js */
+/* import-globals-from calendar-views-utils.js */
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
 /**
  * Namespace object to hold functions related to the today pane.
  */
 var TodayPane = {
   paneViews: null,
@@ -115,24 +115,66 @@ var TodayPane = {
         if (this.start === null) {
           this.setDay(cal.dtz.now());
         }
         if (document.getElementById("today-minimonth-box").isVisible()) {
           document.getElementById("today-minimonth").setAttribute("freebusy", "true");
         }
       }
       if (todoIsVisible) {
-        prepareCalendarToDoUnifinder();
+        // Add listener to update the date filters.
+        getViewDeck().addEventListener("dayselect", event => {
+          this.updateCalendarToDoUnifinder();
+        });
+        this.updateCalendarToDoUnifinder();
       }
     }
 
     document.dispatchEvent(new CustomEvent("viewresize", { bubbles: true }));
   },
 
   /**
+   * Updates the applied filter and show completed view of the unifinder todo.
+   *
+   * @param {String} [filter] - The filter name to set.
+   */
+  updateCalendarToDoUnifinder: function(filter) {
+    let tree = document.getElementById("unifinder-todo-tree");
+
+    // Set up hiding completed tasks for the unifinder-todo tree
+    filter = filter || tree.getAttribute("filterValue") || "throughcurrent";
+    tree.setAttribute("filterValue", filter);
+
+    document
+      .querySelectorAll('menuitem[command="calendar_task_filter_todaypane_command"][type="radio"]')
+      .forEach(item => {
+        if (item.getAttribute("value") == filter) {
+          item.setAttribute("checked", "true");
+        } else {
+          item.removeAttribute("checked");
+        }
+      });
+
+    let showCompleted = document.getElementById("show-completed-checkbox").checked;
+    if (!showCompleted) {
+      let filterProps = tree.mFilter.getDefinedFilterProperties(filter);
+      if (filterProps) {
+        filterProps.status =
+          (filterProps.status || filterProps.FILTER_STATUS_ALL) &
+          (filterProps.FILTER_STATUS_INCOMPLETE | filterProps.FILTER_STATUS_IN_PROGRESS);
+        filter = filterProps;
+      }
+    }
+
+    // update the filter
+    tree.showCompleted = showCompleted;
+    tree.updateFilter(filter);
+  },
+
+  /**
    * Go to month/week/day views when double-clicking a label inside miniday
    */
   onDoubleClick: function(aEvent) {
     if (aEvent.button == 0) {
       if (aEvent.target.id == "datevalue-label") {
         switchCalendarView("day", true);
       } else if (aEvent.target.parentNode.id == "weekdayNameContainer") {
         switchCalendarView("day", true);
@@ -404,17 +446,17 @@ var TodayPane = {
 
   /**
    * Update the period headers in the agenda listbox using the today pane's
    * start date.
    */
   updatePeriod: function() {
     agendaListbox.refreshPeriodDates(this.start.clone());
     if (document.getElementById("todo-tab-panel").isVisible()) {
-      updateCalendarToDoUnifinder();
+      this.updateCalendarToDoUnifinder();
     }
   },
 
   /**
    * Display a certain section in the minday/minimonth part of the todaypane.
    *
    * @param aSection      The section to display
    */
--- a/calendar/base/content/today-pane.xul
+++ b/calendar/base/content/today-pane.xul
@@ -24,17 +24,16 @@
   <script src="chrome://calendar/content/today-pane.js"/>
   <script src="chrome://calendar/content/agenda-listbox-utils.js"/>
   <script src="chrome://calendar/content/calendar-management.js"/>
   <script src="chrome://calendar/content/calendar-dnd-listener.js"/>
   <script src="chrome://calendar/content/calendar-item-editing.js"/>
 
   <script src="chrome://calendar/content/calFilter.js"/>
   <script src="chrome://calendar/content/calendar-task-tree-utils.js"/>
-  <script src="chrome://calendar/content/calendar-unifinder-todo.js"/>
 
   <calendar-modevbox id="today-pane-panel"
                      mode="mail,calendar,task"
                      modewidths="200,200,200"
                      modesplitterstates="open,open,open"
                      refcontrol="calendar_toggle_todaypane_command"
                      persist="modewidths">
     <sidebarheader align="center">
--- a/calendar/base/jar.mn
+++ b/calendar/base/jar.mn
@@ -32,17 +32,16 @@ calendar.jar:
     content/calendar-statusbar.js                               (content/calendar-statusbar.js)
     content/calendar-task-editing.js                            (content/calendar-task-editing.js)
     content/calendar-task-tree-utils.js                         (content/calendar-task-tree-utils.js)
     content/calendar-task-tree-view.js                          (content/calendar-task-tree-view.js)
     content/calendar-task-tree.js                               (content/calendar-task-tree.js)
     content/calendar-task-view.js                               (content/calendar-task-view.js)
     content/calendar-task-view.xul                              (content/calendar-task-view.xul)
     content/calendar-ui-utils.js                                (content/calendar-ui-utils.js)
-    content/calendar-unifinder-todo.js                          (content/calendar-unifinder-todo.js)
     content/calendar-unifinder.js                               (content/calendar-unifinder.js)
     content/calendar-unifinder.xul                              (content/calendar-unifinder.xul)
     content/calendar-views-utils.js                             (content/calendar-views-utils.js)
     content/calendar-views.js                                   (content/calendar-views.js)
     content/calendar-editable-item.js                           (content/calendar-editable-item.js)
     content/calendar-views.xul                                  (content/calendar-views.xul)
     content/calendar-alarm-dialog.js                            (content/dialogs/calendar-alarm-dialog.js)
     content/calendar-alarm-dialog.xul                           (content/dialogs/calendar-alarm-dialog.xul)