Bug 329582 - Remove gCalendarWindow. r=dbo
authorMartin Schroeder <mschroeder@mozilla.x-home.org>
Tue, 21 Oct 2008 14:09:31 +0200
changeset 665 1b5f6939cb84907a0b5cf5e2f57e82ffd3507d3d
parent 664 296018803281c17882610eb01e8a80b018f8ec7e
child 666 5bf762b71c0d6a3f798c3f5e9fedc60978181984
push idunknown
push userunknown
push dateunknown
reviewersdbo
bugs329582
Bug 329582 - Remove gCalendarWindow. r=dbo
calendar/base/content/calendar-views.js
calendar/resources/content/calendar.js
calendar/resources/content/calendarWindow.js
calendar/resources/jar.mn
calendar/sunbird/base/content/calendar-menubar.inc
calendar/sunbird/base/content/calendar-sets.inc
calendar/sunbird/base/content/calendar.xul
calendar/sunbird/base/content/sunbird-scripts.inc
--- a/calendar/base/content/calendar-views.js
+++ b/calendar/base/content/calendar-views.js
@@ -247,29 +247,29 @@ var calendarViewController = {
 /**
  * This function provides a neutral way to switch between views.
  * XXX Kind of confusing. This function calls the app specific function, which
  * again calls the common switchToView function. They should be consolidated in
  * a different bug.
  */
 function showCalendarView(type) {
     if (isSunbird()) {
-        gCalendarWindow.switchToView(type);
+        sbSwitchToView(type);
     } else {
         ltnShowCalendarView(type);
     }
 }
 
 /**
  * This function acts like the above, but does not bring the view to the front
  * if the application is showing other elements (i.e Lightning).
  */
 function selectCalendarView(type) {
     if (isSunbird()) {
-        gCalendarWindow.switchToView(type);
+        sbSwitchToView(type);
     } else {
         ltnSelectCalendarView(type);
     }
 }
 
 /**
  * This function does the common steps to switch between views. Should be called
  * from app-specific view switching functions
--- a/calendar/resources/content/calendar.js
+++ b/calendar/resources/content/calendar.js
@@ -16,19 +16,19 @@
  * The Initial Developer of the Original Code is
  * OEone Corporation.
  * Portions created by the Initial Developer are Copyright (C) 2001
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s): Garth Smedley <garths@oeone.com>
  *                 Mike Potter <mikep@oeone.com>
  *                 Colin Phillips <colinp@oeone.com>
- *                 Karl Guertin <grayrest@grayrest.com> 
+ *                 Karl Guertin <grayrest@grayrest.com>
  *                 Mike Norton <xor@ivwnet.com>
- *                 ArentJan Banck <ajbanck@planet.nl> 
+ *                 ArentJan Banck <ajbanck@planet.nl>
  *                 Eric Belhaire <belhaire@ief.u-psud.fr>
  *                 Matthew Willis <lilmatt@mozilla.com>
  *                 Joey Minta <jminta@gmail.com>
  *                 Dan Mosedale <dan.mosedale@oracle.com>
  *                 Philipp Kewisch <mozilla@kewis.ch>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -39,46 +39,20 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-/***** calendar
-* AUTHOR
-*   Garth Smedley
-*
-* NOTES
-*   Code for the calendar.
-*
-*   What is in this file:
-*     - Global variables and functions - Called directly from the XUL
-*     - Several classes:
-*  
-* IMPLEMENTATION NOTES 
-*
-**********
-*/
-
-// single global instance of CalendarWindow
-var gCalendarWindow;
-
-/*-----------------------------------------------------------------
- *  G L O B A L     C A L E N D A R      F U N C T I O N S
- */
-
-/** 
+/**
  * Called from calendar.xul window onload.
  */
 function calendarInit() {
-    // set up the CalendarWindow instance
-    gCalendarWindow = new CalendarWindow();
-
     // Take care of common initialization
     commonInitCalendar();
 
     var toolbox = document.getElementById("calendar-toolbox");
     toolbox.customizeDone = CalendarToolboxCustomizeDone;
 
     // Setup the offline manager
     calendarOfflineManager.init();
@@ -124,25 +98,25 @@ function handleCommandLine(aComLine) {
                 calurl.push(param);
                 break;
            default:
                 // no-op
                 break;
         }
     }
 
-    //Look for arguments without a flag.
-    //This is needed to handle double-click on Windows and Linux.
+    // Look for arguments without a flag.
+    // This is needed to handle double-click on Windows and Linux.
     if (comLine.length >= 1) {
         for (var i = 0; i < comLine.length; i++) {
             if (!comLine.getArgument(i).match(/^-/) &&
                 !comLine.getArgument(i).match(/^\s/)) {
                 calurl.push( comLine.getArgument(i) );
             } else {
-            comLine.removeArguments(i, i);
+                comLine.removeArguments(i, i);
             }
         }
     }
 
     //subscribe to all files in the calurl array
     for (var i = 0; i < calurl.length; i++) {
         var uri = comLine.resolveURI(calurl[i]);
         var cal = getCalendarManager().createCalendar("ics", uri);
@@ -171,33 +145,32 @@ function refreshUIBits() {
     } catch (exc) {
         ASSERT(false, exc);
     }
 
     // and schedule again...
     scheduleMidnightUpdate(refreshUIBits);
 }
 
-/** 
+/**
  * Steps to be taken when the sunbird calendar window is unloaded.
  */
 function calendarFinish() {
     // Workaround to make the selected tab persist. See bug 249552.
     var tabbox = document.getElementById("tablist");
     tabbox.setAttribute("selectedIndex", tabbox.selectedIndex);
 
     // Finish the offline manager
     calendarOfflineManager.uninit();
 
     // Common finish steps
     commonFinishCalendar();
 }
 
-function closeCalendar()
-{
+function closeCalendar() {
     self.close();
 }
 
 function openPreferences() {
     // Check to see if the prefwindow is already open
     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                        .getService(Components.interfaces.nsIWindowMediator);
 
@@ -213,34 +186,74 @@ function openPreferences() {
                        (instApply ? "dialog=no" : "modal");
 
         var url = "chrome://calendar/content/preferences/preferences.xul";
 
         openDialog(url, "Preferences", features);
     }
 }
 
-function CalendarCustomizeToolbar()
-{
+function CalendarCustomizeToolbar() {
   // Disable the toolbar context menu items
   var menubar = document.getElementById("main-menubar");
-  for (var i = 0; i < menubar.childNodes.length; ++i)
+  for (var i = 0; i < menubar.childNodes.length; ++i) {
     menubar.childNodes[i].setAttribute("disabled", true);
-    
+  }
+
   var cmd = document.getElementById("cmd_CustomizeToolbars");
   cmd.setAttribute("disabled", "true");
 
   window.openDialog("chrome://global/content/customizeToolbar.xul", "CustomizeToolbar",
                     "chrome,all,dependent", document.getElementById("calendar-toolbox"));
 }
 
-function CalendarToolboxCustomizeDone(aToolboxChanged)
-{
+function CalendarToolboxCustomizeDone(aToolboxChanged) {
   // Re-enable parts of the UI we disabled during the dialog
   var menubar = document.getElementById("main-menubar");
-  for (var i = 0; i < menubar.childNodes.length; ++i)
+  for (var i = 0; i < menubar.childNodes.length; ++i) {
     menubar.childNodes[i].setAttribute("disabled", false);
+  }
   var cmd = document.getElementById("cmd_CustomizeToolbars");
   cmd.removeAttribute("disabled");
 
   // XXX Shouldn't have to do this, but I do
   window.focus();
 }
+
+function changeNumberOfWeeks(menuitem) {
+  currentView().weeksInView = menuitem.value;
+}
+
+function pickAndGoToDate() {
+  var initialDate = currentView().selectedDay.getInTimezone(floating()).jsDate;
+  var callback = function receiveAndGoToDate(pickedDate) {
+    currentView().goToDay(jsDateToDateTime(pickedDate));
+    getMinimonth().value = pickedDate;
+  };
+  openDialog("chrome://sunbird/content/calendar-gotodate-dialog.xul",
+             "calendar-gotodate-dialog",
+             "chrome,modal",
+             {callback: callback, date: initialDate});
+}
+
+function minimonthPick(newDate) {
+  var cdt = jsDateToDateTime(newDate, currentView().timezone);
+  cdt.isDate = true;
+  currentView().goToDay(cdt);
+}
+
+function sbSwitchToView(newView) {
+  var mwWeeksCommand = document.getElementById("menu-numberofweeks-inview");
+  if (newView == "multiweek") {
+      mwWeeksCommand.removeAttribute("disabled");
+  } else {
+      mwWeeksCommand.setAttribute("disabled", true);
+  }
+
+  // Call the common view switching code in calendar-views.js
+  switchToView(newView);
+
+  var labelAttribute = "label-" + newView + "-view";
+  var prevCommand = document.getElementById("calendar-go-menu-previous");
+  prevCommand.setAttribute("label", prevCommand.getAttribute(labelAttribute));
+  var nextCommand = document.getElementById("calendar-go-menu-next");
+  nextCommand.setAttribute("label", nextCommand.getAttribute(labelAttribute));
+}
deleted file mode 100644
--- a/calendar/resources/content/calendarWindow.js
+++ /dev/null
@@ -1,95 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is OEone Calendar Code, released October 31st, 2001.
- *
- * The Initial Developer of the Original Code is
- * OEone Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s): Garth Smedley <garths@oeone.com>
- *                 Mike Potter <mikep@oeone.com>
- *                 Eric Belhaire <belhaire@ief.u-psud.fr>
- *                 Robin Edrenius <robin.edrenius@gmail.com>
- *                 Joey Minta <jminta@gmail.com>
- *                 Philipp Kewisch <mozilla@kewis.ch>
- *                 Martin Schroeder <mschroeder@mozilla.x-home.org>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-function CalendarWindow() {
-   /** This object only exists to keep too many things from breaking during the
-    *   switch to the new views
-   **/
-   this.currentView = {
-       changeNumberOfWeeks: function(menuitem) {
-           var mwView = document.getElementById("view-deck").selectedPanel;
-           mwView.weeksInView = menuitem.value;
-       }
-   };
-}
-
-CalendarWindow.prototype.pickAndGoToDate = function calWin_pickAndGoToDate() {
-  var initialDate = currentView().selectedDay.getInTimezone(floating()).jsDate;
-  var callback = function receiveAndGoToDate(pickedDate) {
-    currentView().goToDay(jsDateToDateTime(pickedDate));
-    getMinimonth().value = pickedDate;
-  };
-  openDialog("chrome://sunbird/content/calendar-gotodate-dialog.xul",
-             "calendar-gotodate-dialog",
-             "chrome,modal",
-             {callback: callback, date: initialDate});
-}
-
-CalendarWindow.prototype.goToDay = function calWin_goToDay(newDate) {
-    var view = document.getElementById("view-deck").selectedPanel;
-    var cdt = Components.classes["@mozilla.org/calendar/datetime;1"]
-                        .createInstance(Components.interfaces.calIDateTime);
-    cdt.year = newDate.getFullYear();
-    cdt.month = newDate.getMonth();
-    cdt.day = newDate.getDate();
-    cdt.isDate = true;
-    cdt.timezone = view.timezone;
-    view.goToDay(cdt);
-}
-
-CalendarWindow.prototype.switchToView = function calWin_switchToView(newView) {
-    var mwWeeksCommand = document.getElementById("menu-numberofweeks-inview");
-    if (newView == "multiweek") {
-        mwWeeksCommand.removeAttribute("disabled");
-    } else {
-        mwWeeksCommand.setAttribute("disabled", true);
-    }
-
-    // Call the common view switching code in calendar-views.js
-    switchToView(newView);
-
-    var labelAttribute = "label-" + newView + "-view";
-    var prevCommand = document.getElementById("calendar-go-menu-previous");
-    prevCommand.setAttribute("label", prevCommand.getAttribute(labelAttribute));
-    var nextCommand = document.getElementById("calendar-go-menu-next");
-    nextCommand.setAttribute("label", nextCommand.getAttribute(labelAttribute));
-}
--- a/calendar/resources/jar.mn
+++ b/calendar/resources/jar.mn
@@ -1,13 +1,12 @@
 #filter substitution
 calendar.jar:
 % content calendar %content/calendar/
     content/calendar/calendar.js                           (content/calendar.js)
-    content/calendar/calendarWindow.js                     (content/calendarWindow.js)
     content/calendar/calendarCreation.xul                  (content/calendarCreation.xul)
     content/calendar/calendarCreation.js                   (content/calendarCreation.js)
     content/calendar/clipboard.js                          (content/clipboard.js)
 *   content/calendar/printDialog.js                        (content/printDialog.js)    
     content/calendar/printDialog.xul                       (content/printDialog.xul)
     content/calendar/publish.js                            (content/publish.js)
     content/calendar/publishDialog.js                      (content/publishDialog.js)    
     content/calendar/publishDialog.xul                     (content/publishDialog.xul)
--- a/calendar/sunbird/base/content/calendar-menubar.inc
+++ b/calendar/sunbird/base/content/calendar-menubar.inc
@@ -286,17 +286,17 @@
            <menuitem id="completed-tasks-inview-checkbox-1"
                      type="checkbox"
                      label="&calendar.completedtasks.checkbox.label;"
                      accesskey="&calendar.completedtasks.checkbox.accesskey;"
                      observes="calendar_toggle_show_completed_in_view_command"/>
            <menu id="menu-numberofweeks-inview"
                  label="&sunbird.menu.numberofweeks.label;"
                  accesskey="&sunbird.menu.numberofweeks.accesskey;"
-                 oncommand="gCalendarWindow.currentView.changeNumberOfWeeks(event.target)"
+                 oncommand="changeNumberOfWeeks(event.target)"
                  disabled="true">
            <menupopup>
              <menuitem type="radio"
                        value="2"
                        name="menunbofweeks"
                        label="&sunbird.menu.numberofweeks.2;"/>
              <menuitem type="radio"
                        value="3"
@@ -336,17 +336,17 @@
                      observes="calendar_go_to_today_command"/>
            <menuitem id="calendar-go-menu-date"
                      key="go_to_date_key"
                      label="&goDateCmd.label;"
                      accesskey="&goDateCmd.accesskey;"
                      observes="go_date_command"/>
            <menuseparator/>
            <!-- Label is set appropriate to the variable newView in 
-                switchToView(newView) of calendarWindow.js -->
+                sbSwitchToView(newView) of calendar.js -->
            <menuitem id="calendar-go-menu-previous"
                      label=""
                      label-day-view="&goPreviousCmd.day.label;"
                      label-week-view="&goPreviousCmd.week.label;"
                      label-multiweek-view="&goPreviousCmd.week.label;"
                      label-month-view="&goPreviousCmd.month.label;"
                      accesskey="&goPreviousCmd.accesskey;"
                      observes="calendar_view_prev_command"/>
--- a/calendar/sunbird/base/content/calendar-sets.inc
+++ b/calendar/sunbird/base/content/calendar-sets.inc
@@ -62,17 +62,17 @@
   <command id="cmd_showStatusBar" oncommand="goToggleToolbar('status-bar', 'menu_showStatusBar');"/>
   <command id="cmd_showTaskBox" oncommand="goToggleToolbar('todo-tab-panel', 'menu_showTaskBox'); goToggleToolbar('calendar-todo-splitter');"/>
 
   <command id="Tools:Addons" oncommand="goOpenAddons();"/>
 
   <!-- Sunbird specific commands -->
   <command id="open_local_calendar_command" oncommand="openLocalCalendar()"/>
 
-  <command id="go_date_command" oncommand="gCalendarWindow.pickAndGoToDate()"/>
+  <command id="go_date_command" oncommand="pickAndGoToDate()"/>
   <command id="cmd_quitApplication"     oncommand="goQuitApplication()"/>
 	
   <command id="close_calendar_command" oncommand="closeCalendar()"/>
 
 #ifdef XP_MACOSX
   <command id="minimizeWindowCmd" oncommand="window.minimize();"/>
   <command id="zoomWindowCmd" oncommand="zoomWindow();"/>
 #endif
--- a/calendar/sunbird/base/content/calendar.xul
+++ b/calendar/sunbird/base/content/calendar.xul
@@ -167,17 +167,17 @@
         </tabs>
         <tabpanels flex="1">
           <tabpanel>
             <vbox flex="1" align="center">
               <spacer id="spaceaboveleftminimonth" flex="1" orient="vertical"/>
               <minimonth id="calMinimonth"
                          maxheight="300"
                          freebusy="true"
-                         onchange="gCalendarWindow.goToDay( this.value );"/>
+                         onchange="minimonthPick(this.value);"/>
               <spacer id="spacebelowleftminimonth" flex="1" orient="vertical"/>
             </vbox>
           </tabpanel>
       
           <tabpanel id="tablist-calendarlist">
             <!-- This will be overlayed by calendar-calendars-list.xul -->
             <tree id="calendar-list-tree-widget" flex="1"/>
           </tabpanel>
--- a/calendar/sunbird/base/content/sunbird-scripts.inc
+++ b/calendar/sunbird/base/content/sunbird-scripts.inc
@@ -42,17 +42,16 @@
 # ***** END LICENSE BLOCK *****
 
 #ifdef XP_MACOSX
   <!-- Needed for Mac OS X "Window" menu -->
   <script type="application/javascript" src="chrome://sunbird/content/hiddenWindow.js"/>
 #endif
 
   <script type="application/javascript" src="chrome://calendar/content/calendar.js"/>
-  <script type="application/javascript" src="chrome://calendar/content/calendarWindow.js"/>
   <script type="application/javascript" src="chrome://sunbird/content/calendar-offline.js"/>
   <script type="application/javascript" src="chrome://calendar/content/migration.js"/>
 
   <!-- NEEDED FOR APPLICATION SUPPORT -->
   <script type="application/javascript" src="chrome://sunbird/content/applicationUtil.js"/>
   <script type="application/javascript" src="chrome://calendar/content/calApplicationUtils.js"/>
   <script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
   <script type="application/javascript" src="chrome://global/content/printUtils.js"/>