!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 var selectedServer = null;
40 var nsPrefBranch = null;
41
OnInit
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 function OnInit()
43 {
44 var title = null;
45 var titleElement = null;
46 var brandName = null;
47 var acctType = null;
48 var acctName = null;
49 var brandBundle;
50 var messengerBundle;
51
52 try {
53 if (!nsPrefBranch) {
54 var prefService = Components.classes["@mozilla.org/preferences-service;1"];
55 prefService = prefService.getService();
56 prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
57
58 nsPrefBranch = prefService.getBranch(null);
59 }
60 }
61 catch (ex) {
62 dump("error getting pref service. "+ex+"\n");
63 }
64
65 // Set the header for the page.
66 // Title containts the brand name of the application and the account
67 // type (mail/news) and the name of the account
68 try {
69 // Get title element from the document
70 titleElement = document.getElementById("AccountCentralTitle");
71
72 // Get the brand name
73 brandBundle = document.getElementById("bundle_brand");
74 brandName = brandBundle.getString("brandShortName");
75
76 // Get the account type
77 messengerBundle = document.getElementById("bundle_messenger");
78 selectedServer = GetSelectedServer();
79 var serverType = selectedServer.type;
80 if (serverType == "nntp")
81 acctType = messengerBundle.getString("newsAcctType");
82 else
83 acctType = messengerBundle.getString("mailAcctType");
84
85 // Get the account name
86 var msgFolder = GetSelectedMsgFolder();
87 acctName = msgFolder.prettyName;
88
89 title = messengerBundle.getFormattedString("acctCentralTitleFormat",
90 [brandName,
91 acctType,
92 acctName]);
93
94 titleElement.setAttribute("value", title);
95
96 // Display and collapse items presented to the user based on account type
97 var protocolInfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + serverType];
98 protocolInfo = protocolInfo.getService(Components.interfaces.nsIMsgProtocolInfo);
99 ArrangeAccountCentralItems(selectedServer, protocolInfo, msgFolder);
100 }
101 catch(ex) {
102 dump("Error -> " + ex + "\n");
103 }
104 }
105
106 // Show items in the AccountCentral page depending on the capabilities
107 // of the given account
ArrangeAccountCentralItems
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
108 function ArrangeAccountCentralItems(server, protocolInfo, msgFolder)
109 {
110 try {
111 var displayRssHeader = server.type == 'rss';
112
113 /***** Email header and items : Begin *****/
114
115 // Read Messages
116 var canGetMessages = protocolInfo.canGetMessages;
117 SetItemDisplay("ReadMessages", canGetMessages && !displayRssHeader);
118
119 // Compose Messages link
120 var showComposeMsgLink = protocolInfo.showComposeMsgLink;
121 SetItemDisplay("ComposeMessage", showComposeMsgLink);
122
123 // Junk mail settings
124 var canControlJunkEmail = protocolInfo.canGetIncomingMessages && protocolInfo.canGetMessages && false; // && false, until ready for prime time
125 SetItemDisplay("JunkSettingsMail", canControlJunkEmail);
126
127 var displayEmailHeader = (canGetMessages || showComposeMsgLink || canControlJunkEmail) && !displayRssHeader;
128 // Display Email header, only if any of the items are displayed
129 SetItemDisplay("EmailHeader", displayEmailHeader);
130
131 /***** Email header and items : End *****/
132
133 /***** News header and items : Begin *****/
134
135 // Subscribe to Newsgroups
136 var canSubscribe = (msgFolder.canSubscribe) && !(protocolInfo.canGetMessages);
137 SetItemDisplay("SubscribeNewsgroups", canSubscribe);
138
139 // Junk news settings
140 var canControlJunkNews = protocolInfo.canGetIncomingMessages && !(protocolInfo.canGetMessages) && false; // && false, until ready for prime time
141 SetItemDisplay("JunkSettingsNews", canControlJunkNews);
142
143 var displayNewsHeader = canSubscribe || canControlJunkNews;
144 // Display News header, only if any of the items are displayed
145 SetItemDisplay("NewsHeader", displayNewsHeader);
146
147 /***** News header and items : End *****/
148
149 /***** RSS header and items : Begin *****/
150
151 SetItemDisplay("rssHeader", displayRssHeader);
152 SetItemDisplay("SubscribeRSS", displayRssHeader);
153
154 /***** RSS header and items : End *****/
155
156 // If neither of above sections exist, collapse section separators
157 if (!(displayNewsHeader || displayEmailHeader || displayRssHeader)) {
158 CollapseSectionSeparators("MessagesSection.separator", false);
159 }
160
161 /***** Accounts : Begin *****/
162
163 var canShowCreateAccount = !nsPrefBranch.prefIsLocked("mail.disable_new_account_addition");
164 SetItemDisplay("CreateAccount", canShowCreateAccount);
165
166 /***** Accounts : End *****/
167
168 /***** Advanced Features header and items : Begin *****/
169
170 // Search Messages
171 var canSearchMessages = server.canSearchMessages;
172 SetItemDisplay("SearchMessages", canSearchMessages);
173
174 // Create Filters
175 var canHaveFilters = server.canHaveFilters;
176 SetItemDisplay("CreateFilters", canHaveFilters);
177
178 // Subscribe to IMAP Folders
179 var canSubscribeImapFolders = msgFolder.canSubscribe && protocolInfo.canGetMessages;
180 SetItemDisplay("SubscribeImapFolders", canSubscribeImapFolders);
181
182 // Offline Settings
183 var supportsOffline = (server.offlineSupportLevel != 0);
184 SetItemDisplay("OfflineSettings", supportsOffline);
185
186 var displayAdvFeatures = canSearchMessages || canHaveFilters ||
187 canSubscribeImapFolders|| supportsOffline;
188 // Display Adv Features header, only if any of the items are displayed
189 SetItemDisplay("AdvancedFeaturesHeader", displayAdvFeatures);
190
191 /***** Advanced Featuers header and items : End *****/
192 }
193 catch (ex) {
194 dump("Error is setting AccountCentral Items : " + ex + "\n");
195 }
196 }
197
198 // Collapse the item if the item feature is not supported
SetItemDisplay
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
199 function SetItemDisplay(elemId, displayThisItem)
200 {
201 if (!displayThisItem) {
202 var elem = document.getElementById(elemId);
203 elem.setAttribute("collapsed", true);
204
205 var separatorId = elemId + ".separator";
206 var elemSeparator = document.getElementById(separatorId);
207 elemSeparator.setAttribute("collapsed", true);
208 }
209 }
210
211 // Collapse section separators
CollapseSectionSeparators
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
212 function CollapseSectionSeparators(separatorBaseId)
213 {
214 for (var i=1; i <= 3; i++) {
215 var separatorId = separatorBaseId + i;
216 var separator = document.getElementById(separatorId);
217 separator.setAttribute("collapsed", true);
218 }
219 }
220
221 // From the current folder tree, return the selected server
GetSelectedServer
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
222 function GetSelectedServer()
223 {
224 var folderURI = window.parent.GetSelectedFolderURI();
225 var server = GetServer(folderURI);
226 return server;
227 }
228
229 // From the current folder tree, return the selected folder
GetSelectedMsgFolder
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
230 function GetSelectedMsgFolder()
231 {
232 var folderURI = window.parent.GetSelectedFolderURI();
233 var msgFolder = window.parent.GetMsgFolderFromUri(folderURI, true);
234 return msgFolder;
235 }
236
237 // Open Inbox for selected server.
238 // If needed, open th twsity and select Inbox.
ReadMessages
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
239 function ReadMessages()
240 {
241 try {
242 window.parent.OpenInboxForServer(selectedServer);
243 }
244 catch(ex) {
245 dump("Error -> " + ex + "\n");
246 }
247 }
248
249 // Trigger composer for a new message
ComposeAMessage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
250 function ComposeAMessage(event)
251 {
252 window.parent.MsgNewMessage(null);
253 }
254
255 // Open AccountManager to view settings for a given account
256 // selectPage: the xul file name for the viewing page,
257 // null for the account main page, other pages are
258 // 'am-server.xul', 'am-copies.xul', 'am-offline.xul',
259 // 'am-addressing.xul', 'am-smtp.xul'
ViewSettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
260 function ViewSettings(selectPage)
261 {
262 window.parent.MsgAccountManager(selectPage);
263 }
264
265 // Open AccountWizard to create an account
CreateNewAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
266 function CreateNewAccount()
267 {
268 window.parent.msgOpenAccountWizard();
269 }
270
271 // Bring up search interface for selected account
SearchMessages
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
272 function SearchMessages()
273 {
274 window.parent.MsgSearchMessages();
275 }
276
277 // Open filters window
CreateMsgFilters
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
278 function CreateMsgFilters()
279 {
280 window.parent.MsgFilters(null, null);
281 }
282
283 // Open Subscribe dialog
Subscribe
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
284 function Subscribe()
285 {
286 var server = GetSelectedServer();
287 if (server && server.type == 'rss')
288 window.parent.openSubscriptionsDialog(server.rootFolder);
289 else
290 window.parent.MsgSubscribe();
291 }
292
293 // Open junk mail settings dialog
JunkSettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
294 function JunkSettings()
295 {
296 window.parent.MsgJunkMail();
297 }