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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/* 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 initMailIdentitiesRow, saveMailIdentitySelection,
notifyOnIdentitySelection, initForceEmailScheduling,
saveForceEmailScheduling, updateForceEmailSchedulingControl */
/* global MozElements, addMenuItem, gCalendar */
var { MailServices } = ChromeUtils.import("resource:///modules/MailServices.jsm");
var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs");
XPCOMUtils.defineLazyGetter(this, "gIdentityNotification", () => {
return new MozElements.NotificationBox(element => {
document.getElementById("no-identity-notification").append(element);
});
});
/**
* Initialize the email identity row. Shared between the calendar creation
* dialog and the calendar properties dialog.
*
* @param {calICalendar} aCalendar - The calendar being created or edited.
*/
function initMailIdentitiesRow(aCalendar) {
if (!aCalendar) {
document.getElementById("calendar-email-identity-row").toggleAttribute("hidden", true);
}
let imipIdentityDisabled = aCalendar.getProperty("imip.identity.disabled");
document
.getElementById("calendar-email-identity-row")
.toggleAttribute("hidden", imipIdentityDisabled);
if (imipIdentityDisabled) {
// If the imip identity is disabled, we don't have to set up the
// menulist.
return;
}
// If there is no transport but also no organizer id, then the
// provider has not statically configured an organizer id. This is
// basically what happens when "None" is selected.
let menuPopup = document.getElementById("email-identity-menupopup");
// Remove all children from the email list to avoid duplicates if the list
// has already been populated during a previous step in the calendar
// creation wizard.
while (menuPopup.hasChildNodes()) {
menuPopup.lastChild.remove();
}
addMenuItem(menuPopup, cal.l10n.getLtnString("imipNoIdentity"), "none");
let identities;
if (aCalendar && aCalendar.aclEntry && aCalendar.aclEntry.hasAccessControl) {
identities = aCalendar.aclEntry.getOwnerIdentities();
} else {
identities = MailServices.accounts.allIdentities;
}
for (let identity of identities) {
addMenuItem(menuPopup, identity.identityName, identity.key);
}
let sel = aCalendar.getProperty("imip.identity");
if (sel) {
sel = sel.QueryInterface(Ci.nsIMsgIdentity);
}
document.getElementById("email-identity-menulist").value = sel ? sel.key : "none";
}
/**
* Returns the selected email identity. Shared between the calendar creation
* dialog and the calendar properties dialog.
*
* @param {calICalendar} aCalendar - The calendar for the identity selection.
* @returns {string} The key of the selected nsIMsgIdentity or 'none'.
*/
function getMailIdentitySelection(aCalendar) {
let sel = "none";
if (aCalendar) {
let imipIdentityDisabled = aCalendar.getProperty("imip.identity.disabled");
let selItem = document.getElementById("email-identity-menulist").selectedItem;
if (!imipIdentityDisabled && selItem) {
sel = selItem.getAttribute("value");
}
}
return sel;
}
/**
* Persists the selected email identity. Shared between the calendar creation
* dialog and the calendar properties dialog.
*
* @param {calICalendar} aCalendar - The calendar for the identity selection.
*/
function saveMailIdentitySelection(aCalendar) {
if (aCalendar) {
let sel = getMailIdentitySelection(aCalendar);
// no imip.identity.key will default to the default account/identity, whereas
// an empty key indicates no imip; that identity will not be found
aCalendar.setProperty("imip.identity.key", sel == "none" ? "" : sel);
}
}
/**
* Displays a warning if the user doesn't assign an email identity to a
* calendar. Shared between the calendar creation dialog and the calendar
* properties dialog.
*
* @param {calICalendar} aCalendar - The calendar for the identity selection.
*/
function notifyOnIdentitySelection(aCalendar) {
gIdentityNotification.removeAllNotifications();
let msg = cal.l10n.getLtnString("noIdentitySelectedNotification");
let sel = getMailIdentitySelection(aCalendar);
if (sel == "none") {
gIdentityNotification.appendNotification(
"noIdentitySelected",
{
label: msg,
priority: gIdentityNotification.PRIORITY_WARNING_MEDIUM,
},
null
);
} else {
gIdentityNotification.removeAllNotifications();
}
}
/**
* Initializing calendar creation wizard and properties dialog to display the
* option to enforce email scheduling for outgoing scheduling operations.
* Used in the calendar properties dialog.
*/
function initForceEmailScheduling() {
if (gCalendar && gCalendar.type == "caldav") {
let checkbox = document.getElementById("force-email-scheduling");
let curStatus = checkbox.getAttribute("checked") == "true";
let newStatus = gCalendar.getProperty("forceEmailScheduling") || curStatus;
if (curStatus != newStatus) {
if (newStatus) {
checkbox.setAttribute("checked", "true");
} else {
checkbox.removeAttribute("checked");
}
}
updateForceEmailSchedulingControl();
} else {
document.getElementById("calendar-force-email-scheduling-row").toggleAttribute("hidden", true);
}
}
/**
* Persisting the calendar property to enforce email scheduling. Used in the
* calendar properties dialog.
*/
function saveForceEmailScheduling() {
if (gCalendar && gCalendar.type == "caldav") {
let checkbox = document.getElementById("force-email-scheduling");
if (checkbox && checkbox.getAttribute("disable-capability") != "true") {
let status = checkbox.getAttribute("checked") == "true";
gCalendar.setProperty("forceEmailScheduling", status);
}
}
}
/**
* Updates the forceEmailScheduling control based on the currently assigned
* email identity to this calendar. Used in the calendar properties dialog.
*/
function updateForceEmailSchedulingControl() {
let checkbox = document.getElementById("force-email-scheduling");
if (
gCalendar &&
gCalendar.getProperty("capabilities.autoschedule.supported") &&
getMailIdentitySelection(gCalendar) != "none"
) {
checkbox.removeAttribute("disable-capability");
checkbox.removeAttribute("disabled");
} else {
checkbox.setAttribute("disable-capability", "true");
checkbox.setAttribute("disabled", "true");
}
}
|