!import
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Alec Flett <alecf@netscape.com>
24 * Seth Spitzer <sspitzer@netscape.com>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 var gPrefsBundle;
41 var gOnMailServersPage;
42 var gOnNewsServerPage;
43 var gHideIncoming;
44
serverPageValidate
45 function serverPageValidate()
46 {
47 var smtpServerName = trim(document.getElementById("smtphostname").value);
48 var incomingServerName = trim(document.getElementById("incomingServer").value);
49 var newsServerName = trim(document.getElementById("newsServer").value);
50
51 if ((gOnMailServersPage &&
52 ((hostnameIsIllegal(incomingServerName) && !gHideIncoming) ||
53 (hostnameIsIllegal(smtpServerName)))) ||
54 (gOnNewsServerPage && hostnameIsIllegal(newsServerName))) {
55 var alertText = gPrefsBundle.getString("enterValidHostname");
56 window.alert(alertText);
57 return false;
58 }
59
60 /* if this is for a server that doesn't require a username,
61 * check if the account exists.
62 * for other types, we check after the user provides the username (see aw-login.js)
63 */
64 var pageData = parent.GetPageData();
65 var serverType = parent.getCurrentServerType(pageData);
66 var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + serverType].getService(Components.interfaces.nsIMsgProtocolInfo);
67 if (!protocolinfo.requiresUsername) {
68 var userName = parent.getCurrentUserName(pageData);
69 var hostName;
70 if (gOnMailServersPage)
71 hostName = incomingServerName;
72 else if (gOnNewsServerPage)
73 hostName = newsServerName;
74
75 if (parent.AccountExists(userName,hostName,serverType)) {
76 alertText = gPrefsBundle.getString("accountExists");
77 window.alert(alertText);
78 return false;
79 }
80 }
81
82 setPageData(pageData, "server", "servertype", serverType);
83
84 if (gOnMailServersPage) {
85 // If we have hidden the incoming server dialogs, we don't want
86 // to set the server to an empty value here
87 if (!gHideIncoming) {
88 setPageData(pageData, "server", "hostname", incomingServerName);
89 }
90 setPageData(pageData, "server", "smtphostname", smtpServerName);
91 }
92 else if (gOnNewsServerPage) {
93 setPageData(pageData, "newsserver", "hostname", newsServerName);
94 }
95
96 return true;
97 }
98
serverPageInit
99 function serverPageInit() {
100 gOnMailServersPage = (document.documentElement.currentPage.id == "serverpage");
101 gOnNewsServerPage = (document.documentElement.currentPage.id == "newsserver");
102 if (gOnNewsServerPage)
103 {
104 var newsServer = document.getElementById("newsServer");
105 var pageData = parent.GetPageData();
106 try
107 {
108 newsServer.value = pageData.newsserver.hostname.value;
109 }
110 catch (ex){}
111 }
112
113 gHideIncoming = false;
114 if (gCurrentAccountData && gCurrentAccountData.wizardHideIncoming)
115 gHideIncoming = true;
116
117 var incomingServerbox = document.getElementById("incomingServerbox");
118 var serverTypeBox = document.getElementById("serverTypeBox");
119 if (incomingServerbox && serverTypeBox) {
120 if (gHideIncoming) {
121 incomingServerbox.setAttribute("hidden", "true");
122 serverTypeBox.setAttribute("hidden", "true");
123 }
124 else {
125 incomingServerbox.removeAttribute("hidden");
126 serverTypeBox.removeAttribute("hidden");
127 }
128 }
129
130 // Server type selection (pop3 or imap) is for mail accounts only
131 var pageData = parent.GetPageData();
132 var isMailAccount = pageData.accounttype.mailaccount.value;
133 var isOtherAccount = pageData.accounttype.otheraccount.value;
134 if (isMailAccount && !gHideIncoming) {
135 var serverTypeRadioGroup = document.getElementById("servertype");
136 /*
137 * Check to see if the radiogroup has any value. If there is no
138 * value, this must be the first time user visting this page in the
139 * account setup process. So, the default is set to pop3. If there
140 * is a value (it's used automatically), user has already visited
141 * page and server type selection is done. Once user visits the page,
142 * the server type value from then on will persist (whether the selection
143 * came from the default or the user action).
144 */
145 if (!serverTypeRadioGroup.value) {
146 /*
147 * if server type was set to imap in isp data, then
148 * we preset the server type radio group accordingly,
149 * otherwise, use pop3 as the default.
150 */
151 var serverTypeRadioItem = document.getElementById(pageData.server &&
152 pageData.server.servertype && pageData.server.servertype.value == "imap" ?
153 "imap" : "pop3");
154 serverTypeRadioGroup.selectedItem = serverTypeRadioItem; // Set pop3 server type as default selection
155 }
156 setServerType();
157 setDeferStorage(); // set the initial value correctly
158 }
159 else if (isOtherAccount) {
160 document.getElementById("incomingServerSeparator").hidden = true;
161 document.getElementById("deferStorageBox").hidden = true;
162 }
163
164 gPrefsBundle = document.getElementById("bundle_prefs");
165 var smtpServer = null;
166 var smtpCreateNewServer = gCurrentAccountData && gCurrentAccountData.smtpCreateNewServer;
167
168 // Don't use the default smtp server if smtp server creation was explicitly
169 // requested in isp rdf.
170 if (parent.smtpService.defaultServer && !smtpCreateNewServer) {
171 smtpServer = parent.smtpService.defaultServer;
172 setPageData(pageData, "identity", "smtpServerKey", smtpServer.key);
173 }
174
175 var noSmtpBox = document.getElementById("noSmtp");
176 var haveSmtpBox = document.getElementById("haveSmtp");
177
178 var boxToHide;
179 var boxToShow;
180
181 if (pageData.server && pageData.server.hostname) {
182 var incomingServerTextBox = document.getElementById("incomingServer");
183 if (incomingServerTextBox && incomingServerTextBox.value == "")
184 incomingServerTextBox.value = pageData.server.hostname.value;
185 }
186
187 if (pageData.server && pageData.server.smtphostname && smtpCreateNewServer) {
188 var smtpTextBox = document.getElementById("smtphostname");
189 if (smtpTextBox && smtpTextBox.value == "")
190 smtpTextBox.value = pageData.server.smtphostname.value;
191 boxToShow = haveSmtpBox;
192 boxToHide = noSmtpBox;
193 }
194
195 if (smtpServer && smtpServer.hostname) {
196 // we have a hostname, so modify and show the static text and
197 // store the value of the default smtp server in the textbox.
198 modifyStaticText(smtpServer.hostname, "1")
199 var smtpTextBox = document.getElementById("smtphostname");
200 if (smtpTextBox && smtpTextBox.value == "")
201 smtpTextBox.value = smtpServer.hostname;
202 boxToShow = haveSmtpBox;
203 boxToHide = noSmtpBox;
204 } else {
205 // no default hostname yet
206 boxToShow = noSmtpBox;
207 boxToHide = haveSmtpBox;
208 }
209
210 if (boxToHide)
211 boxToHide.setAttribute("hidden", "true");
212
213 if (boxToShow)
214 boxToShow.removeAttribute("hidden");
215 }
216
modifyStaticText
217 function modifyStaticText(smtpMod, smtpBox)
218 {
219 // modify the value in the smtp display if we already have a
220 // smtp server so that the single string displays the hostname
221 // or username for the smtp server.
222 var smtpStatic = document.getElementById("smtpStaticText"+smtpBox);
223 if (smtpStatic && smtpStatic.hasChildNodes())
224 smtpStatic.childNodes[0].nodeValue = smtpStatic.getAttribute("prefix") +
225 smtpMod + smtpStatic.getAttribute("suffix");
226 }
227
setServerType
228 function setServerType()
229 {
230 var pageData = parent.GetPageData();
231 var serverType = document.getElementById("servertype").value;
232 var deferStorageBox = document.getElementById("deferStorageBox");
233 deferStorageBox.hidden = serverType == "imap";
234 document.getElementById("incomingServerSeparator").hidden = false;
235 setPageData(pageData, "server", "servertype", serverType);
236 }
237
setDeferStorage
238 function setDeferStorage()
239 {
240 var pageData = parent.GetPageData();
241 var deferStorage = (document.getElementById("deferStorage")).checked;
242 setPageData(pageData, "server", "deferStorage", deferStorage);
243 }