From 97734170c818b56ef9c8279b315b495d5603ab4b Mon Sep 17 00:00:00 2001 From: Martin Schroeder Date: Tue, 14 Dec 2010 00:10:57 +0100 Subject: [PATCH] Bug 516802 - Refactor & cleanup mode and calendar view switching + today pane code. r=Fallen --- .../base/content/calendar-chrome-startup.js | 2 +- calendar/base/content/calendar-common-sets.js | 24 +++++++ .../base/content/calendar-common-sets.xul | 9 +-- calendar/base/content/calendar-views.js | 35 +++------- .../content/messenger-overlay-sidebar.css | 39 ----------- .../content/messenger-overlay-sidebar.js | 70 +++++-------------- .../content/messenger-overlay-sidebar.xul | 30 +++++--- calendar/lightning/jar.mn | 1 - .../sunbird/base/content/calendar-menubar.inc | 2 +- 9 files changed, 77 insertions(+), 135 deletions(-) diff --git a/calendar/base/content/calendar-chrome-startup.js b/calendar/base/content/calendar-chrome-startup.js index 808fe90ec2..eed316b0ca 100644 --- a/calendar/base/content/calendar-chrome-startup.js +++ b/calendar/base/content/calendar-chrome-startup.js @@ -43,7 +43,7 @@ function commonInitCalendar() { loadCalendarManager(); // Restore the last shown calendar view - selectCalendarView(getLastCalendarView()); + switchCalendarView(getLastCalendarView(), false); // set up the unifinder prepareCalendarToDoUnifinder(); diff --git a/calendar/base/content/calendar-common-sets.js b/calendar/base/content/calendar-common-sets.js index 949e712e05..5a28c92eb1 100644 --- a/calendar/base/content/calendar-common-sets.js +++ b/calendar/base/content/calendar-common-sets.js @@ -19,6 +19,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Martin Schroeder * * 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 @@ -76,6 +77,11 @@ var calendarController = { "calendar_toggle_orientation_command": true, "calendar_toggle_workdays_only_command": true, + "calendar_day-view_command": true, + "calendar_week-view_command": true, + "calendar_multiweek-view_command": true, + "calendar_month-view_command": true, + "calendar_task_filter_command": true, "calendar_reload_remote_calendars": true, "calendar_show_unifinder_command": true, @@ -190,6 +196,10 @@ var calendarController = { // The following commands need calendar mode, be careful when // changing things. + case "calendar_day-view_command": + case "calendar_week-view_command": + case "calendar_multiweek-view_command": + case "calendar_month-view_command": case "calendar_show_unifinder_command": case "calendar_mode_calendar": return this.isInMode("calendar"); @@ -364,6 +374,20 @@ var calendarController = { case "calendar_toggle_workdays_only_command": toggleWorkdaysOnly(); break; + + case "calendar_day-view_command": + switchCalendarView("day", true); + break; + case "calendar_week-view_command": + switchCalendarView("week", true); + break; + case "calendar_multiweek-view_command": + switchCalendarView("multiweek", true); + break; + case "calendar_month-view_command": + switchCalendarView("month", true); + break; + default: if (this.defaultController && !this.isCalendarInForeground()) { // If calendar is not in foreground, let the default controller take diff --git a/calendar/base/content/calendar-common-sets.xul b/calendar/base/content/calendar-common-sets.xul index 4289a07aa5..d16c8d3ea8 100755 --- a/calendar/base/content/calendar-common-sets.xul +++ b/calendar/base/content/calendar-common-sets.xul @@ -22,6 +22,7 @@ - Contributor(s): - Simon Paquet - Berend Cornelius + - Martin Schroeder - - 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 @@ -90,10 +91,10 @@ - - - - + + + + diff --git a/calendar/base/content/calendar-views.js b/calendar/base/content/calendar-views.js index 0f276b21ec..bc4dab443a 100644 --- a/calendar/base/content/calendar-views.js +++ b/calendar/base/content/calendar-views.js @@ -273,34 +273,17 @@ 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. * - * @param type The type of view to show - * @param event (optional) A DOM event that caused the view to show. + * @param aType The type of view to select. + * @param aShow If true, the calendar view is forced to be shown, i.e. + * bringing the view to the front if the application is + * showing other elements (Lightning). */ -function showCalendarView(type, event) { - if (isSunbird()) { - sbSwitchToView(type, event); - } else if (document.getElementById('switch2calendar').getAttribute('checked')) { - ltnShowCalendarView(type, event); - } - onCalendarViewResize(event); -} - -/** - * This function acts like showCalendarView, but does not bring the view to the front - * if the application is showing other elements (i.e Lightning). - * - * @see showCalendarView - * @param type The type of view to select. - */ -function selectCalendarView(type) { - if (isSunbird()) { - sbSwitchToView(type); +function switchCalendarView(aType, aShow) { + if (cal.isSunbird()) { + sbSwitchToView(aType); } else { - ltnSelectCalendarView(type); + ltnSwitchCalendarView(aType, aShow); } } @@ -387,6 +370,8 @@ function switchToView(aViewType) { view.goToDay(selectedDay); view.setSelectedItems(currentSelection.length, currentSelection); + + onCalendarViewResize(); } /** diff --git a/calendar/lightning/content/messenger-overlay-sidebar.css b/calendar/lightning/content/messenger-overlay-sidebar.css index c27e6ee015..e69de29bb2 100644 --- a/calendar/lightning/content/messenger-overlay-sidebar.css +++ b/calendar/lightning/content/messenger-overlay-sidebar.css @@ -1,39 +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 Lightning code. - * - * The Initial Developer of the Original Code is Oracle Corporation - * Portions created by the Initial Developer are Copyright (C) 2005 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Mike Shaver - * - * 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 ***** */ - -#calendar-view-box { - visibility: collapse; -} diff --git a/calendar/lightning/content/messenger-overlay-sidebar.js b/calendar/lightning/content/messenger-overlay-sidebar.js index 70a48df8a7..9cdcc63df6 100644 --- a/calendar/lightning/content/messenger-overlay-sidebar.js +++ b/calendar/lightning/content/messenger-overlay-sidebar.js @@ -195,9 +195,6 @@ function ltnOnLoad(event) { // Take care of common initialization commonInitCalendar(); - // Hide the calendar view so it doesn't push the status-bar offscreen - collapseElement(document.getElementById("calendar-view-box")); - // Add an unload function to the window so we don't leak any listeners window.addEventListener("unload", ltnFinish, false); @@ -249,34 +246,25 @@ function refreshUIBits() { } /** - * Select the calendar view in the background, not switching to calendar mode if - * in mail mode. + * Switch the calendar view, and optionally switch to calendar mode. + * + * @param aType The type of view to select. + * @param aShow If true, the mode will be switched to calendar if not + * already there. */ -function ltnSelectCalendarView(type) { - gLastShownCalendarView = type; +function ltnSwitchCalendarView(aType, aShow) { + gLastShownCalendarView = aType; - // Sunbird/Lightning Common view switching code - switchToView(type); - -} - -/** - * Show the calendar view, also switching to calendar mode if in mail mode - */ -function ltnShowCalendarView(type) -{ - gLastShownCalendarView = type; - - if (gCurrentMode != 'calendar') { - // This function in turn calls showCalendarView(), so return afterwards. + if (aShow && gCurrentMode != "calendar") { + // This function in turn calls switchToView(), so return afterwards. ltnSwitch2Calendar(); return; } - ltnSelectCalendarView(type); + // Sunbird/Lightning common view switching code + switchToView(aType); } - /** * This function has the sole responsibility to switch back to * mail mode (by calling ltnSwitch2Mail()) if we are getting @@ -402,7 +390,6 @@ function openInvitationsDialog() { /** * the current mode is set to a string defining the current * mode we're in. allowed values are: - * - 'mode' * - 'mail' * - 'calendar' * - 'task' @@ -415,13 +402,6 @@ var gCurrentMode = 'mail'; function ltnSwitch2Mail() { if (gCurrentMode != 'mail') { - var switch2mail = document.getElementById("switch2mail"); - var switch2calendar = document.getElementById("switch2calendar"); - var switch2task = document.getElementById("switch2task"); - switch2mail.setAttribute("checked", "true"); - switch2calendar.removeAttribute("checked"); - switch2task.removeAttribute("checked"); - gCurrentMode = 'mail'; document.getElementById("modeBroadcaster").setAttribute("mode", gCurrentMode); @@ -436,24 +416,15 @@ function ltnSwitch2Mail() { function ltnSwitch2Calendar() { if (gCurrentMode != 'calendar') { - var switch2mail = document.getElementById("switch2mail"); - var switch2calendar = document.getElementById("switch2calendar"); - var switch2task = document.getElementById("switch2task"); - switch2mail.removeAttribute("checked"); - switch2calendar.setAttribute("checked", "true"); - switch2task.removeAttribute("checked"); - gCurrentMode = 'calendar'; document.getElementById("modeBroadcaster").setAttribute("mode", gCurrentMode); // display the calendar panel on the display deck - var viewBox = document.getElementById("calendar-view-box"); - uncollapseElement(viewBox); - var deck = document.getElementById("calendarDisplayDeck"); - deck.selectedPanel = viewBox; + let deck = document.getElementById("calendarDisplayDeck"); + deck.selectedPanel = document.getElementById("calendar-view-box"); // show the last displayed type of calendar view - showCalendarView(gLastShownCalendarView); + switchToView(gLastShownCalendarView); document.commandDispatcher.updateCommands('calendar_commands'); window.setCursor("auto"); @@ -466,21 +437,12 @@ function ltnSwitch2Calendar() { function ltnSwitch2Task() { if (gCurrentMode != 'task') { - var switch2mail = document.getElementById("switch2mail"); - var switch2calendar = document.getElementById("switch2calendar"); - var switch2task = document.getElementById("switch2task"); - switch2mail.removeAttribute("checked"); - switch2calendar.removeAttribute("checked"); - switch2task.setAttribute("checked", "true"); - gCurrentMode = 'task'; document.getElementById("modeBroadcaster").setAttribute("mode", gCurrentMode); // display the task panel on the display deck - var taskBox = document.getElementById("calendar-task-box"); - uncollapseElement(taskBox); - var deck = document.getElementById("calendarDisplayDeck"); - deck.selectedPanel = taskBox; + let deck = document.getElementById("calendarDisplayDeck"); + deck.selectedPanel = document.getElementById("calendar-task-box"); document.commandDispatcher.updateCommands('calendar_commands'); window.setCursor("auto"); diff --git a/calendar/lightning/content/messenger-overlay-sidebar.xul b/calendar/lightning/content/messenger-overlay-sidebar.xul index 6a69efd0c7..027cb7ad95 100644 --- a/calendar/lightning/content/messenger-overlay-sidebar.xul +++ b/calendar/lightning/content/messenger-overlay-sidebar.xul @@ -168,38 +168,39 @@ - + + command="calendar_day-view_command"/> + command="calendar_week-view_command"/> + command="calendar_multiweek-view_command"/> + command="calendar_month-view_command"/> + key="openLightningKey" + autocheck="false"> + + + key="openTasksKey" + autocheck="false"> + + - -