!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
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 * Håkan Waara <hwaara@chello.se>
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41 var gCurrentDomain;
42 var gPrefsBundle;
43
identityPageValidate
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
44 function identityPageValidate()
45 {
46 var name = document.getElementById("fullName").value;
47
48 if (!name) {
49 var alertText = gPrefsBundle.getString("enterName");
50 window.alert(alertText);
51 return false;
52 }
53 if (!validateEmail()) return false;
54
55 var pageData = parent.GetPageData();
56 setPageData(pageData, "identity", "fullName", name);
57
58 return true;
59 }
60
61 // this is kind of wacky.. basically it validates the email entered in
62 // the text field to make sure it's in the form "user@host"..
63 //
64 // However, if there is a current domain (retrieved during onInit)
65 // then we have to do some special tricks:
66 // - if the user ALSO entered an @domain, then we just chop it off
67 // - at some point it would be useful to keep the @domain, in case they
68 // wish to override the domain.
validateEmail
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
69 function validateEmail()
70 {
71 var emailElement = document.getElementById("email");
72 var email = trim(emailElement.value);
73 var emailArray = email.split('@');
74
75 if (gCurrentDomain) {
76 // check if user entered an @ sign even though we have a domain
77 if (emailArray.length >= 2) {
78 email = emailArray[0];
79 emailElement.value = email;
80 }
81
82 if (!email.length || containsIllegalChar(email)) {
83 var alertText = gPrefsBundle.getString("enterValidEmailPrefix");
84 window.alert(alertText);
85 return false;
86 }
87 }
88
89 else {
90 if (emailArray.length != 2 ||
91 !emailArray[0].length ||
92 !emailArray[1].length ||
93 containsIllegalChar(emailArray[0]) ||
94 containsIllegalChar(emailArray[1])) {
95 alertText = gPrefsBundle.getString("enterValidEmail");
96 window.alert(alertText);
97 return false;
98 }
99 }
100
101 var pageData = parent.GetPageData();
102 setPageData(pageData, "identity", "email", email);
103
104 return true;
105 }
106
107 // This function mimics validateEmail() except that
108 // it runs on prefilled text and does not alert the user.
109 // This is for the case when the code appends the domain
110 // unnecessarily.
111 // This simply gets rid of "@domain" from "foo@domain"
112
fixPreFilledEmail
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
113 function fixPreFilledEmail()
114 {
115 var emailElement = document.getElementById("email");
116 var email = emailElement.value;
117 var emailArray = email.split('@');
118
119 if (gCurrentDomain) {
120 // check if user entered an @ sign even though we have a domain
121 if (emailArray.length >= 2) {
122 email = emailArray[0];
123 emailElement.value = email;
124 }
125 }
126 }
127
128
129
130 // This function checks for common illegal
131 // characters. This shouldn't be too strict, since
132 // we do more extensive tests later. -Håkan
containsIllegalChar
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
133 function containsIllegalChar(aString)
134 {
135 for (var i=0; i < aString.length; i++) {
136 var code = aString.charCodeAt(i);
137 if (code > 127)
138 return true; // non-ASCII
139 else if (code == 9 || code == 10 || code == 11 || code == 32)
140 return true; // white space
141 else if (code == 64)
142 return true; // '@'
143 }
144 return false;
145 }
146
identityPageInit
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
147 function identityPageInit()
148 {
149 gCurrentDomain = null;
150 gPrefsBundle = document.getElementById("bundle_prefs");
151 clearEmailTextItems();
152 setEmailDescriptionText();
153 checkForDomain();
154 checkForFullName();
155 checkForEmail();
156 fixPreFilledEmail();
157 }
158
clearEmailTextItems
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
159 function clearEmailTextItems()
160 {
161 var emailDescText = document.getElementById("emailDescText");
162
163 if (emailDescText.firstChild)
164 emailDescText.removeChild(emailDescText.firstChild);
165
166 var postEmailText = document.getElementById("postEmailText");
167 postEmailText.setAttribute("value", "");
168 }
169
170 // Use email example data that ISP has provided. ISP data, if avaialble
171 // for the choice user has made, will be read into CurrentAccountData.
172 // Default example data from properties will be used when the info is missing.
setEmailDescriptionText
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
173 function setEmailDescriptionText()
174 {
175 var emailDescText = document.getElementById("emailDescText");
176 var emailFieldLabel = document.getElementById("emailFieldLabel");
177 var currentAccountData = parent.gCurrentAccountData;
178
179 var displayText = null;
180 var emailFieldLabelData = null;
181 var setDefaultEmailDescStrings = true;
182
183 // Set the default field label
184 emailFieldLabel.setAttribute("value", gPrefsBundle.getString("emailFieldText"));
185
186 // Get values for customized data from current account
187 if (currentAccountData)
188 {
189 var emailProvider = currentAccountData.emailProviderName;
190 var sampleEmail = currentAccountData.sampleEmail;
191 var sampleUserName = currentAccountData.sampleUserName;
192 var emailIDDesc = currentAccountData.emailIDDescription;
193 var emailIDTitle = currentAccountData.emailIDFieldTitle;
194
195 if (emailProvider &&
196 sampleEmail &&
197 sampleUserName &&
198 emailIDDesc &&
199 emailIDTitle)
200 {
201 // Get email description data
202 displayText = gPrefsBundle.getFormattedString("customizedEmailText",
203 [emailProvider,
204 emailIDDesc,
205 sampleEmail,
206 sampleUserName]);
207
208 // Set emailfield label
209 emailFieldLabelData = emailIDTitle;
210 emailFieldLabel.setAttribute("value", emailFieldLabelData);
211
212 // Need to display customized data. Turn off default settings.
213 setDefaultEmailDescStrings = false;
214 }
215 }
216
217 if (setDefaultEmailDescStrings)
218 {
219 // Check for obtained values and set with default values if needed
220 var username = gPrefsBundle.getString("exampleEmailUserName");
221 var domain = gPrefsBundle.getString("exampleEmailDomain");
222
223 displayText = gPrefsBundle.getFormattedString("defaultEmailText",
224 [username, domain]);
225 }
226
227 // Create a text nodes with text to be displayed
228 var emailDescTextNode = document.createTextNode(displayText);
229
230 // Display the dynamically generated text for email description
231 emailDescText.appendChild(emailDescTextNode);
232 }
233
234 // retrieve the current domain from the parent wizard window,
235 // and update the UI to add the @domain static text
checkForDomain
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
236 function checkForDomain()
237 {
238 var accountData = parent.gCurrentAccountData;
239 if (!accountData) return;
240 if (!accountData.domain) return;
241
242 // save in global variable
243 gCurrentDomain = accountData.domain;
244
245 var postEmailText = document.getElementById("postEmailText");
246 postEmailText.setAttribute("value", "@" + gCurrentDomain);
247 }
248
checkForFullName
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
249 function checkForFullName() {
250 var name = document.getElementById("fullName");
251 if (name.value=="") {
252 try {
253 var userInfo = Components.classes["@mozilla.org/userinfo;1"].getService(Components.interfaces.nsIUserInfo);
254 name.value = userInfo.fullname;
255 }
256 catch (ex) {
257 // dump ("checkForFullName failed: " + ex + "\n");
258 }
259 }
260 }
261
checkForEmail
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
262 function checkForEmail()
263 {
264 var email = document.getElementById("email");
265 var pageData = parent.GetPageData();
266 if (pageData && pageData.identity && pageData.identity.email) {
267 email.value = pageData.identity.email.value;
268 }
269 if (email.value=="") {
270 try {
271 var userInfo = Components.classes["@mozilla.org/userinfo;1"].getService(Components.interfaces.nsIUserInfo);
272 email.value = userInfo.emailAddress;
273 }
274 catch (ex) {
275 // dump ("checkForEmail failed: " + ex + "\n");
276 }
277 }
278 }