!import
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is mozilla.org code.
15 *
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2000-2002
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * David Bienvenu <bienvenu@mozilla.org>
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38 var gMsgFolder;
39 var gServerTypeFolder = null;
40 var gPreselectedFolderURI = null;
41 var gParentMsgWindow = null;
42 var gNameTextbox;
43 var gOldName;
44 var gOkButton;
45 var gLockedPref = null;
46
47 var gRebuildSummaryFileCallback;
48
49 // services used
50 var RDF;
51
52 // corresponds to MSG_FOLDER_FLAG_OFFLINE
53 const MSG_FOLDER_FLAG_OFFLINE = 0x8000000
54
55 // corresponds to MSG_FOLDER_FLAG_CHECK_NEW
56 const MSG_FOLDER_FLAG_CHECK_NEW = 0x20000000
57
58 // corresponds to MSG_FOLDER_FLAG_INBOX
59 const MSG_FOLDER_FLAG_INBOX = 0x1000
60
61 // The folderPropsSink is the class that gets notified of an imap folder's properties
62
63 var gFolderPropsSink = {
setFolderType
64 setFolderType: function(folderTypeString)
65 {
66 var typeLabel = document.getElementById("folderType.text");
67 if (typeLabel)
68 {
69 typeLabel.setAttribute("value",folderTypeString);
70 }
71 // get the element for the folder type label and set value on it.
72 },
73
setFolderTypeDescription
74 setFolderTypeDescription: function(folderDescription)
75 {
76 var folderTypeLabel = document.getElementById("folderDescription.text");
77 if (folderTypeLabel)
78 folderTypeLabel.setAttribute("value", folderDescription);
79 },
80
setFolderPermissions
81 setFolderPermissions: function(folderPermissions)
82 {
83 var permissionsLabel = document.getElementById("folderPermissions.text");
84 var descTextNode = document.createTextNode(folderPermissions);
85 permissionsLabel.appendChild(descTextNode);
86 },
87
serverDoesntSupportACL
88 serverDoesntSupportACL : function()
89 {
90 var typeLabel = document.getElementById("folderTypeLabel");
91 if (typeLabel)
92 typeLabel.setAttribute("hidden", "true");
93 var permissionsLabel = document.getElementById("permissionsDescLabel");
94 if (permissionsLabel)
95 permissionsLabel.setAttribute("hidden", "true");
96
97 },
98
setQuotaStatus
99 setQuotaStatus : function(folderQuotaStatus)
100 {
101 var quotaStatusLabel = document.getElementById("folderQuotaStatus");
102 if(quotaStatusLabel)
103 quotaStatusLabel.setAttribute("value", folderQuotaStatus);
104 },
105
showQuotaData
106 showQuotaData : function(showData)
107 {
108 var quotaStatusLabel = document.getElementById("folderQuotaStatus");
109 var folderQuotaData = document.getElementById("folderQuotaData");
110
111 if(quotaStatusLabel && folderQuotaData)
112 {
113 quotaStatusLabel.hidden = showData;
114 folderQuotaData.hidden = ! showData;
115 }
116 },
117
setQuotaData
118 setQuotaData : function(root, usedKB, maxKB)
119 {
120 var quotaRoot = document.getElementById("quotaRoot");
121 if (quotaRoot)
122 quotaRoot.setAttribute("value", '"' + root + '"');
123
124 var percentage = (maxKB != 0) ? Math.round(usedKB / maxKB * 100) : 0;
125
126 var quotaPercentageBar = document.getElementById("quotaPercentageBar");
127 if (quotaPercentageBar)
128 quotaPercentageBar.setAttribute("value", percentage);
129
130 var bundle = document.getElementById("bundle_messenger");
131 if(bundle)
132 {
133 var usedFreeCaption = bundle.getFormattedString("quotaUsedFree", [usedKB, maxKB], 2);
134 quotaCaption = document.getElementById("quotaUsedFree");
135 if(quotaCaption)
136 quotaCaption.setAttribute("value", usedFreeCaption);
137
138 var percentUsedCaption = bundle.getFormattedString("quotaPercentUsed", [percentage], 1);
139 var percentUsed = document.getElementById("quotaPercentUsed");
140 if(percentUsed)
141 percentUsed.setAttribute("value", percentUsedCaption);
142 }
143 }
144
145 };
146
doEnabling
147 function doEnabling()
148 {
149 gOkButton.disabled = !gNameTextbox.value;
150 }
151
folderPropsOKButton
152 function folderPropsOKButton()
153 {
154 if (gMsgFolder)
155 {
156
157 // set charset attributes
158 var folderCharsetList = document.getElementById("folderCharsetList");
159 gMsgFolder.charset = folderCharsetList.getAttribute("value");
160 gMsgFolder.charsetOverride = document.getElementById("folderCharsetOverride").checked;
161
162 if(document.getElementById("offline.selectForOfflineFolder").checked ||
163 document.getElementById("offline.selectForOfflineNewsgroup").checked)
164 gMsgFolder.setFlag(MSG_FOLDER_FLAG_OFFLINE);
165 else
166 gMsgFolder.clearFlag(MSG_FOLDER_FLAG_OFFLINE);
167
168 if(document.getElementById("folderCheckForNewMessages").checked)
169 gMsgFolder.setFlag(MSG_FOLDER_FLAG_CHECK_NEW);
170 else
171 gMsgFolder.clearFlag(MSG_FOLDER_FLAG_CHECK_NEW);
172
173 var retentionSettings = saveCommonRetentionSettings();
174 retentionSettings.useServerDefaults = document.getElementById("retention.useDefault").checked;
175 gMsgFolder.retentionSettings = retentionSettings;
176
177 }
178
179 try
180 {
181 // This throws an exception when an illegal folder name was entered.
182 okCallback(gNameTextbox.value, gOldName, gPreselectedFolderURI);
183
184 return true;
185 }
186 catch (e)
187 {
188 return false;
189 }
190 }
191
folderPropsOnLoad
192 function folderPropsOnLoad()
193 {
194 gOkButton = document.documentElement.getButton("accept");
195
196 RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
197
198 // look in arguments[0] for parameters
199 if (window.arguments && window.arguments[0]) {
200 if ( window.arguments[0].title ) {
201 document.title = window.arguments[0].title;
202 }
203 if ( window.arguments[0].okCallback ) {
204 top.okCallback = window.arguments[0].okCallback;
205 }
206 if (window.arguments[0].rebuildSummaryCallback)
207 gRebuildSummaryFileCallback = window.arguments[0].rebuildSummaryCallback;
208 }
209
210 // fill in folder name, based on what they selected in the folder pane
211 if (window.arguments[0].preselectedURI) {
212 try {
213 gPreselectedFolderURI = window.arguments[0].preselectedURI;
214 }
215 catch (ex) {
216 }
217 }
218 else {
219 dump("passed null for preselectedURI, do nothing\n");
220 }
221
222 if(window.arguments[0].name)
223 {
224 // Initialize name textbox with the given name and remember this
225 // value so we can tell whether the folder needs to be renamed
226 // when the dialog is accepted.
227 gNameTextbox = document.getElementById("name");
228 gNameTextbox.value = gOldName = window.arguments[0].name;
229
230 // name.setSelectionRange(0,-1);
231 // name.focusTextField();
232 }
233
234 gServerTypeFolder = window.arguments[0].serverType;
235
236 if (window.arguments && window.arguments[0]) {
237 if (window.arguments[0].msgWindow) {
238 gParentMsgWindow = window.arguments[0].msgWindow;
239 }
240 }
241
242 // this hex value come from nsMsgFolderFlags.h
243 var folderResource = RDF.GetResource(gPreselectedFolderURI);
244
245 if (folderResource)
246 gMsgFolder = folderResource.QueryInterface(Components.interfaces.nsIMsgFolder);
247 if (!gMsgFolder)
248 dump("no gMsgFolder preselectfolder uri = "+gPreselectedFolderURI+'\n');
249
250 if (gMsgFolder) {
251 var locationTextbox = document.getElementById("location");
252
253 // Decode the displayed mailbox:// URL as it's useful primarily for debugging,
254 // whereas imap and news urls are sent around.
255 locationTextbox.value = (gServerTypeFolder == "imap" || gServerTypeFolder == "nntp") ?
256 gMsgFolder.folderURL : decodeURI(gMsgFolder.folderURL);
257
258 if (gMsgFolder.canRename)
259 gNameTextbox.removeAttribute("readonly");
260
261 if (gMsgFolder.flags & MSG_FOLDER_FLAG_OFFLINE) {
262
263 if(gServerTypeFolder == "imap" || gServerTypeFolder == "pop3")
264 document.getElementById("offline.selectForOfflineFolder").checked = true;
265
266 if(gServerTypeFolder == "nntp")
267 document.getElementById("offline.selectForOfflineNewsgroup").checked = true;
268 }
269 else {
270 if(gServerTypeFolder == "imap" || gServerTypeFolder == "pop3")
271 document.getElementById("offline.selectForOfflineFolder").checked = false;
272
273 if(gServerTypeFolder == "nntp")
274 document.getElementById("offline.selectForOfflineNewsgroup").checked = false;
275 }
276
277 // select the menu item
278 var folderCharsetList = document.getElementById("folderCharsetList");
279 var elements = folderCharsetList.getElementsByAttribute("value", gMsgFolder.charset);
280 folderCharsetList.selectedItem = elements[0];
281
282 // set override checkbox
283 document.getElementById("folderCharsetOverride").checked = gMsgFolder.charsetOverride;
284
285 // set check for new mail checkbox
286 document.getElementById("folderCheckForNewMessages").checked = gMsgFolder.flags & MSG_FOLDER_FLAG_CHECK_NEW;
287 }
288
289 if (gServerTypeFolder == "imap")
290 {
291 var imapFolder = gMsgFolder.QueryInterface(Components.interfaces.nsIMsgImapMailFolder);
292 if (imapFolder)
293 imapFolder.fillInFolderProps(gFolderPropsSink);
294 }
295
296 var retentionSettings = gMsgFolder.retentionSettings;
297 initCommonRetentionSettings(retentionSettings);
298 document.getElementById("retention.useDefault").checked = retentionSettings.useServerDefaults;
299
300 // select the initial tab
301 if (window.arguments[0].tabID) {
302 try {
303 document.getElementById("folderPropTabBox").selectedTab =
304 document.getElementById(window.arguments[0].tabID);
305 }
306 catch (ex) {}
307 }
308 hideShowControls(gServerTypeFolder);
309 onCheckKeepMsg();
310 onUseDefaultRetentionSettings();
311
312 moveToAlertPosition();
313 }
314
hideShowControls
315 function hideShowControls(serverType)
316 {
317 var controls = document.getElementsByAttribute("hidable", "true");
318 var len = controls.length;
319 for (var i=0; i<len; i++) {
320 var control = controls[i];
321 var hideFor = control.getAttribute("hidefor");
322 if (!hideFor)
323 throw "this should not happen, things that are hidable should have hidefor set";
324
325 var box = getEnclosingContainer(control);
326
327 if (!box)
328 throw "this should not happen, things that are hidable should be in a box";
329
330 // hide unsupported server type
331 // adding support for hiding multiple server types using hideFor="server1,server2"
332 var hideForBool = false;
333 var hideForTokens = hideFor.split(",");
334 for (var j = 0; j < hideForTokens.length; j++) {
335 if (hideForTokens[j] == serverType) {
336 hideForBool = true;
337 break;
338 }
339 }
340
341 if (hideForBool) {
342 box.setAttribute("hidden", "true");
343 }
344 else {
345 box.removeAttribute("hidden");
346 }
347 }
348 // hide the priviliges button if the imap folder doesn't have an admin url
349 // mabye should leave this hidden by default and only show it in this case instead
350 try {
351 var imapFolder = gMsgFolder.QueryInterface(Components.interfaces.nsIMsgImapMailFolder);
352 if (imapFolder)
353 {
354 var privilegesButton = document.getElementById("imap.FolderPrivileges");
355 if (privilegesButton)
356 {
357 if (!imapFolder.hasAdminUrl)
358 privilegesButton.setAttribute("hidden", "true");
359 }
360 }
361 }
362 catch (ex) {}
363
364 // hide "check for new mail" checkbox if this is inbox
365 if (gMsgFolder)
366 {
367 if (gMsgFolder.flags & MSG_FOLDER_FLAG_INBOX)
368 {
369 document.getElementById("folderCheckForNewMessages").setAttribute("hidden", "true");
370 }
371 }
372
373 }
374
getEnclosingContainer
375 function getEnclosingContainer(startNode)
376 {
377 var parent = startNode;
378 var box;
379 while (parent && parent != document)
380 {
381 var isContainer = (parent.getAttribute("iscontrolcontainer") == "true");
382
383 // remember the FIRST container we encounter, or the first controlcontainer
384 if (!box || isContainer) box=parent;
385
386 // break out with a controlcontainer
387 if (isContainer) break;
388 parent = parent.parentNode;
389 }
390 return box;
391 }
392
onOfflineFolderDownload
393 function onOfflineFolderDownload()
394 {
395 // we need to create a progress window and pass that in as the second parameter here.
396 gMsgFolder.downloadAllForOffline(null, gParentMsgWindow);
397 }
398
onFolderPrivileges
399 function onFolderPrivileges()
400 {
401 var imapFolder = gMsgFolder.QueryInterface(Components.interfaces.nsIMsgImapMailFolder);
402 if (imapFolder)
403 imapFolder.folderPrivileges(gParentMsgWindow);
404 // let's try closing the modal dialog to see if it fixes the various problems running this url
405 window.close();
406 }
407
408
onUseDefaultRetentionSettings
409 function onUseDefaultRetentionSettings()
410 {
411 var useDefault = document.getElementById("retention.useDefault").checked;
412 document.getElementById('retention.keepMsg').disabled = useDefault;
413 document.getElementById('retention.keepNewMsgMinLabel').disabled = useDefault;
414 document.getElementById('retention.keepOldMsgMinLabel').disabled = useDefault;
415 }
416
RebuildSummaryInformation
417 function RebuildSummaryInformation()
418 {
419 gRebuildSummaryFileCallback(gMsgFolder);
420 }