/
preferences.addressbook.groupdav.js
205 lines (171 loc) · 7.45 KB
/
preferences.addressbook.groupdav.js
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* preferences.addressbook.groupdav.js - This file is part of "SOGo Connector", a Thunderbird extension.
*
* Copyright: Inverse inc., 2006-2010
* Author: Robert Bolduc, Wolfgang Sourdeau
* Email: support@inverse.ca
* URL: http://inverse.ca
*
* "SOGo Connector" is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation;
*
* "SOGo Connector" is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* "SOGo Connector"; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
function jsInclude(files, target) {
let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
for (let i = 0; i < files.length; i++) {
try {
loader.loadSubScript(files[i], target);
}
catch(e) {
dump("preferences.addressbook.groupdav.js: failed to include '" + files[i] + "'\n" + e + "\n");
}
}
}
jsInclude(["chrome://sogo-connector/content/addressbook/folder-handling.js",
"chrome://sogo-connector/content/general/preference.service.addressbook.groupdav.js",
"chrome://sogo-connector/content/general/mozilla.utils.inverse.ca.js"]);
function SCGetCurrentDirectory() {
let directory = null;
if (window.arguments.length > 0) {
let args = window.arguments[0];
if (args) {
directory = args.selectedDirectory;
}
}
return directory;
}
function onAccept() {
let prefMsgBundle = document.getElementById("preferencesMsgId");
//There has to be at least a description to create a SOGO addressbook
let description = document.getElementById("description").value;
if (!description || description == "") {
alert(prefMsgBundle.getString("missingDescriptionMsg"));
return false;
}
let url = document.getElementById("groupdavURL").value;
if (!url || url == "") {
alert(prefMsgBundle.getString("missingDescriptionURL"));
return false;
}
let readOnly = document.getElementById("readOnly").checked;
if (readOnly) {
onAcceptCardDAV();
}
else {
onAcceptWebDAV();
}
return true;
}
function onAcceptCardDAV() {
let description = document.getElementById("description").value;
let directory = SCGetCurrentDirectory();
if (directory) {
directory.dirName = description;
}
else {
let url = document.getElementById("groupdavURL").value;
SCCreateCardDAVDirectory(description, url);
}
}
function onAcceptWebDAV() {
let prefId;
let description = document.getElementById("description").value;
let directory = SCGetCurrentDirectory();
if (directory && directory.dirPrefId.length > 0) {
directory.dirName = description;
prefId = directory.dirPrefId;
}
else {
// adding a new Addressbook
let abMgr = Components.classes["@mozilla.org/abmanager;1"]
.getService(Components.interfaces.nsIAbManager);
prefId = abMgr.newAddressBook(description, null,
2 /* don't know which values should go in
there but 2 seems to get the job
done */);
}
try {
let groupdavPrefService = new GroupdavPreferenceService(prefId);
groupdavPrefService.setURL(document.getElementById("groupdavURL").value);
groupdavPrefService.setPeriodicSync(document.getElementById("periodicSync").checked);
groupdavPrefService.setPeriodicSyncInterval(document.getElementById("periodicSyncInterval").value);
groupdavPrefService.setNotifications(document.getElementById("notifications").checked);
groupdavPrefService.setNotificationsOnlyIfNotEmpty(document.getElementById("notificationsOnlyIfNotEmpty").checked);
groupdavPrefService.setNotificationsManual(document.getElementById("notificationsManual").checked);
groupdavPrefService.setNotificationsSave(document.getElementById("notificationsSave").checked);
groupdavPrefService.setNotificationsStart(document.getElementById("notificationsStart").checked);
} catch(e) {
}
}
function onLoad() {
let description = "";
let url = "";
let periodicSync = false;
let periodicSyncInterval = 15;
let notifications = true;
let notificationsOnlyIfNotEmpty = false;
let notificationsManual = true;
let notificationsSave = false;
let notificationsStart = true;
let directory = SCGetCurrentDirectory();
if (directory) {
let uri = directory.URI;
let readOnly = (uri.indexOf("moz-abdavdirectory://") == 0);
let roElem = document.getElementById("readOnly");
roElem.setAttribute("checked", readOnly);
roElem.disabled = true;
if (readOnly) {
description = directory.dirName;
directory = directory.wrappedJSObject;
url = directory.serverURL;
}
try {
let groupdavPrefService = new GroupdavPreferenceService(directory.dirPrefId);
description = directory.dirName;
url = groupdavPrefService.getURL();
periodicSync = groupdavPrefService.getPeriodicSync();
periodicSyncInterval = groupdavPrefService.getPeriodicSyncInterval();
notifications = groupdavPrefService.getNotifications();
notificationsOnlyIfNotEmpty = groupdavPrefService.getNotificationsOnlyIfNotEmpty();
notificationsManual = groupdavPrefService.getNotificationsManual();
notificationsSave = groupdavPrefService.getNotificationsSave();
notificationsStart = groupdavPrefService.getNotificationsStart();
} catch(e) {
}
}
// always define values
document.getElementById("description").value = description;
document.getElementById("groupdavURL").value = url;
document.getElementById("periodicSync").checked = periodicSync;
document.getElementById("periodicSyncInterval").value = periodicSyncInterval;
document.getElementById("notifications").checked = notifications;
document.getElementById("notificationsOnlyIfNotEmpty").checked = notificationsOnlyIfNotEmpty;
document.getElementById("notificationsManual").checked = notificationsManual;
document.getElementById("notificationsSave").checked = notificationsSave;
document.getElementById("notificationsStart").checked = notificationsStart;
onUpdateCheck();
}
function onUpdateCheck() {
var psc = document.getElementById("periodicSync").checked;
var nc = document.getElementById("notifications").checked;
document.getElementById("periodicSyncInterval").disabled = !psc;
document.getElementById("notifications").disabled = !psc;
document.getElementById("notificationsOnlyIfNotEmpty").disabled = !nc || !psc;
}
function onShowRestart() {
// show the info about restart
document.getElementById("periodicSync_restart").hidden = false;
}
//TODO:catch the directory delete and delete preferences
function onCancel() {
window.close();
}