1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* 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/. */
/* globals TodayPane, switchToView, gLastShownCalendarView, ensureUnifinderLoaded */
/* exported calSwitchToCalendarMode, calSwitchToMode, calSwitchToTaskMode,
* changeMode
*/
var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
/**
* The current mode defining the current mode we're in. Allowed values are:
* - 'mail'
* - 'calendar'
* - 'task'
* - 'chat'
* - 'calendarEvent'
* - 'calendarTask'
* - 'special' - For special tabs like preferences, add-ons manager, about:xyz, etc.
*
* @global
*/
var gCurrentMode = "mail";
/**
* Changes the mode (gCurrentMode) and adapts the UI to the new mode.
*
* @param {string} [mode="mail"] - the new mode: 'mail', 'calendar', 'task', etc.
*/
function changeMode(mode = "mail") {
gCurrentMode = mode; // eslint-disable-line no-global-assign
document
.querySelectorAll(
`menuitem[command="switch2calendar"],menuitem[command="switch2task"],
toolbarbutton[command="switch2calendar"],toolbarbutton[command="switch2task"]`
)
.forEach(elem => {
elem.setAttribute("checked", elem.getAttribute("value") == gCurrentMode);
});
document.querySelectorAll("calendar-modebox,calendar-modevbox").forEach(elem => {
elem.setAttribute("current", gCurrentMode);
});
TodayPane.onModeModified();
}
/**
* For switching to modes like "mail", "chat", "calendarEvent", "calendarTask", or "special".
* (For "calendar" and "task" modes use calSwitchToCalendarMode and calSwitchToTaskMode.)
*
* @param {string} mode - The mode to switch to.
*/
function calSwitchToMode(mode) {
if (!["mail", "chat", "calendarEvent", "calendarTask", "special"].includes(mode)) {
cal.WARN("Attempted to switch to unknown mode: " + mode);
return;
}
if (gCurrentMode != mode) {
const previousMode = gCurrentMode;
changeMode(mode);
if (previousMode == "calendar" || previousMode == "task") {
document.commandDispatcher.updateCommands("calendar_commands");
}
window.setCursor("auto");
}
}
/**
* Switches to the calendar mode.
*/
function calSwitchToCalendarMode() {
if (gCurrentMode != "calendar") {
changeMode("calendar");
// display the calendar panel on the display deck
document.getElementById("calendar-view-box").collapsed = false;
document.getElementById("calendar-task-box").collapsed = true;
document.getElementById("sidePanelNewEvent").hidden = false;
document.getElementById("sidePanelNewTask").hidden = true;
// show the last displayed type of calendar view
switchToView(gLastShownCalendarView.get());
document.getElementById("calMinimonth").setAttribute("freebusy", "true");
document.commandDispatcher.updateCommands("calendar_commands");
window.setCursor("auto");
// make sure the view is sized correctly
window.dispatchEvent(new CustomEvent("viewresize"));
// Load the unifinder if it isn't already loaded.
ensureUnifinderLoaded();
}
}
/**
* Switches to the task mode.
*/
function calSwitchToTaskMode() {
if (gCurrentMode != "task") {
changeMode("task");
// display the task panel on the display deck
document.getElementById("calendar-view-box").collapsed = true;
document.getElementById("calendar-task-box").collapsed = false;
document.getElementById("sidePanelNewEvent").hidden = true;
document.getElementById("sidePanelNewTask").hidden = false;
document.getElementById("calMinimonth").setAttribute("freebusy", "true");
let tree = document.getElementById("calendar-task-tree");
if (!tree.hasBeenVisible) {
tree.hasBeenVisible = true;
tree.refresh();
}
document.commandDispatcher.updateCommands("calendar_commands");
window.setCursor("auto");
}
}
|