!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
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 Communicator client code, released
15 * March 31, 1998.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or 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 gPublishSiteData;
39 var gPublishDataChanged = false;
40 var gDefaultSiteIndex = -1;
41 var gDefaultSiteName;
42 var gPreviousDefaultSite;
43 var gPreviousTitle;
44 var gSettingsChanged = false;
45 var gSiteDataChanged = false;
46 var gAddNewSite = false;
47 var gCurrentSiteIndex = -1;
48 var gPasswordManagerOn = true;
49
50 // Dialog initialization code
Startup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
51 function Startup()
52 {
53 if (!GetCurrentEditor())
54 {
55 window.close();
56 return;
57 }
58
59 gDialog.SiteList = document.getElementById("SiteList");
60 gDialog.SiteNameInput = document.getElementById("SiteNameInput");
61 gDialog.PublishUrlInput = document.getElementById("PublishUrlInput");
62 gDialog.BrowseUrlInput = document.getElementById("BrowseUrlInput");
63 gDialog.UsernameInput = document.getElementById("UsernameInput");
64 gDialog.PasswordInput = document.getElementById("PasswordInput");
65 gDialog.SavePassword = document.getElementById("SavePassword");
66 gDialog.SetDefaultButton = document.getElementById("SetDefaultButton");
67 gDialog.RemoveSiteButton = document.getElementById("RemoveSiteButton");
68 gDialog.OkButton = document.documentElement.getButton("accept");
69
70 gPublishSiteData = GetPublishSiteData();
71 gDefaultSiteName = GetDefaultPublishSiteName();
72 gPreviousDefaultSite = gDefaultSiteName;
73
74 gPasswordManagerOn = GetBoolPref("signon.rememberSignons");
75 gDialog.SavePassword.disabled = !gPasswordManagerOn;
76
77 InitDialog();
78
79 SetWindowLocation();
80 }
81
InitDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
82 function InitDialog()
83 {
84 // If there's no current site data, start a new item in the Settings panel
85 if (!gPublishSiteData)
86 {
87 AddNewSite();
88 }
89 else
90 {
91 FillSiteList();
92
93 // uncomment next code line if you want preselection of the default
94 // publishing site
95 //InitSiteSettings(gDefaultSiteIndex);
96
97 SetTextboxFocus(gDialog.SiteNameInput);
98 }
99 }
100
FillSiteList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
101 function FillSiteList()
102 {
103 // Prevent triggering SelectSiteList() actions
104 gIsSelecting = true;
105 ClearListbox(gDialog.SiteList);
106 gIsSelecting = false;
107 gDefaultSiteIndex = -1;
108
109 // Fill the site list
110 var count = gPublishSiteData.length;
111 for (var i = 0; i < count; i++)
112 {
113 var name = gPublishSiteData[i].siteName;
114 var item = gDialog.SiteList.appendItem(name);
115 SetPublishItemStyle(item);
116 if (name == gDefaultSiteName)
117 gDefaultSiteIndex = i;
118 }
119 }
120
SetPublishItemStyle
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
121 function SetPublishItemStyle(item)
122 {
123 // Display default site with bold style
124 if (item)
125 {
126 if (item.getAttribute("label") == gDefaultSiteName)
127 item.setAttribute("class", "bold");
128 else
129 item.removeAttribute("class");
130 }
131 }
132
AddNewSite
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
133 function AddNewSite()
134 {
135 // Save any pending changes locally first
136 if (!ApplyChanges())
137 return;
138
139 // Initialize Setting widgets to none of the selected sites
140 InitSiteSettings(-1);
141 gAddNewSite = true;
142
143 SetTextboxFocus(gDialog.SiteNameInput);
144 }
145
RemoveSite
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
146 function RemoveSite()
147 {
148 if (!gPublishSiteData)
149 return;
150
151 var index = gDialog.SiteList.selectedIndex;
152 var item;
153 if (index != -1)
154 {
155 item = gDialog.SiteList.selectedItems[0];
156 var nameToRemove = item.getAttribute("label");
157
158 // Remove one item from site data array
159 gPublishSiteData.splice(index, 1);
160 // Remove item from site list
161 gDialog.SiteList.clearSelection();
162 gDialog.SiteList.removeItemAt(index);
163
164 // Adjust if we removed last item and reselect a site
165 if (index >= gPublishSiteData.length)
166 index--;
167 InitSiteSettings(index);
168
169 if (nameToRemove == gDefaultSiteName)
170 {
171 // Deleting current default -- set to new selected item
172 // Arbitrary, but what else to do?
173 SetDefault();
174 }
175 gSiteDataChanged = true;
176 }
177 }
178
SetDefault
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
179 function SetDefault()
180 {
181 if (!gPublishSiteData)
182 return;
183
184 var index = gDialog.SiteList.selectedIndex;
185 if (index != -1)
186 {
187 gDefaultSiteIndex = index;
188 gDefaultSiteName = gPublishSiteData[index].siteName;
189
190 // Set bold style on new default
191 var item = gDialog.SiteList.firstChild;
192 while (item)
193 {
194 SetPublishItemStyle(item);
195 item = item.nextSibling;
196 }
197 }
198 }
199
200 // Recursion prevention:
201 // Use when you don't want to trigger ApplyChanges and InitSiteSettings
202 var gIsSelecting = false;
203
SelectSiteList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
204 function SelectSiteList()
205 {
206 if (gIsSelecting)
207 return;
208
209 gIsSelecting = true;
210 var newIndex = gDialog.SiteList.selectedIndex;
211
212 // Save any pending changes locally first
213 if (!ApplyChanges())
214 return;
215
216 InitSiteSettings(newIndex);
217
218 gIsSelecting = false;
219 }
220
221 // Use this to prevent recursion in SelectSiteList
SetSelectedSiteIndex
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
222 function SetSelectedSiteIndex(index)
223 {
224 gIsSelecting = true;
225 gDialog.SiteList.selectedIndex = index;
226 gIsSelecting = false;
227 }
228
InitSiteSettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
229 function InitSiteSettings(selectedSiteIndex)
230 {
231 // Index to the site we will need to update if settings changed
232 gCurrentSiteIndex = selectedSiteIndex;
233
234 SetSelectedSiteIndex(selectedSiteIndex);
235 var haveData = (gPublishSiteData && selectedSiteIndex != -1);
236
237 gDialog.SiteNameInput.value = haveData ? gPublishSiteData[selectedSiteIndex].siteName : "";
238 gDialog.PublishUrlInput.value = haveData ? gPublishSiteData[selectedSiteIndex].publishUrl : "";
239 gDialog.BrowseUrlInput.value = haveData ? gPublishSiteData[selectedSiteIndex].browseUrl : "";
240 gDialog.UsernameInput.value = haveData ? gPublishSiteData[selectedSiteIndex].username : "";
241
242 var savePassord = haveData && gPasswordManagerOn;
243 gDialog.PasswordInput.value = savePassord ? gPublishSiteData[selectedSiteIndex].password : "";
244 gDialog.SavePassword.checked = savePassord ? gPublishSiteData[selectedSiteIndex].savePassword : false;
245
246 gDialog.SetDefaultButton.disabled = !haveData;
247 gDialog.RemoveSiteButton.disabled = !haveData;
248 gSettingsChanged = false;
249 }
250
onInputSettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
251 function onInputSettings()
252 {
253 // TODO: Save current data during SelectSite1 and compare here
254 // to detect if real change has occurred?
255 gSettingsChanged = true;
256 }
257
ApplyChanges
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
258 function ApplyChanges()
259 {
260 if (gSettingsChanged && !UpdateSettings())
261 {
262 // Restore selection to previously current site
263 SetSelectedSiteIndex(gCurrentSiteIndex);
264 return false;
265 }
266 return true;
267 }
268
UpdateSettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
269 function UpdateSettings()
270 {
271 // Validate and add new site
272 var newName = TrimString(gDialog.SiteNameInput.value);
273 if (!newName)
274 {
275 ShowInputErrorMessage(GetString("MissingSiteNameError"), gDialog.SiteNameInput);
276 return false;
277 }
278 if (PublishSiteNameExists(newName, gPublishSiteData, gCurrentSiteIndex))
279 {
280 ShowInputErrorMessage(GetString("DuplicateSiteNameError").replace(/%name%/, newName));
281 SetTextboxFocus(gDialog.SiteNameInput);
282 return false;
283 }
284
285 var newUrl = FormatUrlForPublishing(gDialog.PublishUrlInput.value);
286 if (!newUrl)
287 {
288 ShowInputErrorMessage(GetString("MissingPublishUrlError"), gDialog.PublishUrlInput);
289 return false;
290 }
291
292 // Start assuming we're updating existing site at gCurrentSiteIndex
293 var newSiteData = false;
294
295 if (!gPublishSiteData)
296 {
297 // First time used - Create the first site profile
298 gPublishSiteData = new Array(1);
299 gCurrentSiteIndex = 0;
300 newSiteData = true;
301 }
302 else if (gCurrentSiteIndex == -1)
303 {
304 // No currently-selected site,
305 // must be adding a new site
306 // Add new data at the end of list
307 gCurrentSiteIndex = gPublishSiteData.length;
308 newSiteData = true;
309 }
310
311 if (newSiteData)
312 {
313 // Init new site profile
314 gPublishSiteData[gCurrentSiteIndex] = {};
315 gPublishSiteData[gCurrentSiteIndex].docDir = "";
316 gPublishSiteData[gCurrentSiteIndex].otherDir = "";
317 gPublishSiteData[gCurrentSiteIndex].dirList = [""];
318 gPublishSiteData[gCurrentSiteIndex].previousSiteName = newName;
319 }
320
321 gPublishSiteData[gCurrentSiteIndex].siteName = newName;
322 gPublishSiteData[gCurrentSiteIndex].publishUrl = newUrl;
323 gPublishSiteData[gCurrentSiteIndex].browseUrl = FormatUrlForPublishing(gDialog.BrowseUrlInput.value);
324 gPublishSiteData[gCurrentSiteIndex].username = TrimString(gDialog.UsernameInput.value);
325 gPublishSiteData[gCurrentSiteIndex].password= gDialog.PasswordInput.value;
326 gPublishSiteData[gCurrentSiteIndex].savePassword = gDialog.SavePassword.checked;
327
328 if (gCurrentSiteIndex == gDefaultSiteIndex)
329 gDefaultSiteName = newName;
330
331 // When adding the very first site, assume that's the default
332 if (gPublishSiteData.length == 1 && !gDefaultSiteName)
333 {
334 gDefaultSiteName = gPublishSiteData[0].siteName;
335 gDefaultSiteIndex = 0;
336 }
337
338 FillSiteList();
339
340 // Select current site in list
341 SetSelectedSiteIndex(gCurrentSiteIndex);
342
343 // Signal saving data to prefs
344 gSiteDataChanged = true;
345
346 // Clear current site flags
347 gSettingsChanged = false;
348 gAddNewSite = false;
349
350 return true;
351 }
352
onAccept
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
353 function onAccept()
354 {
355 // Save any pending changes locally first
356 if (!ApplyChanges())
357 return false;
358
359 if (gSiteDataChanged)
360 {
361 // Save all local data to prefs
362 SavePublishSiteDataToPrefs(gPublishSiteData, gDefaultSiteName);
363 }
364 else if (gPreviousDefaultSite != gDefaultSiteName)
365 {
366 // only the default site was changed
367 SetDefaultSiteName(gDefaultSiteName);
368 }
369
370 SaveWindowLocation();
371
372 return true;
373 }