~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/editor/ui/dialogs/content/EditorPublishSettings.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

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