!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) 1998-1999
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Charles Manske (cmanske@netscape.com)
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 gInProgress = true;
40 var gPublishData;
41 var gPersistObj;
42 var gTotalFileCount = 0;
43 var gSucceededCount = 0;
44 var gFinished = false;
45 var gPublishingFailed = false;
46 var gFileNotFound = false;
47 var gStatusMessage="";
48
49 var gTimerID;
50 var gAllowEnterKey = false;
51
52 // Publishing error codes
53 // These are translated from C++ error code strings like this:
54 // kFileNotFound = "FILE_NOT_FOUND",
55 const kNetReset = 2152398868; // nsISocketTransportService.idl
56 const kFileNotFound = 2152857618;
57 const kNotConnected = 2152398860; // in netCore.h
58 const kConnectionRefused = 2152398861; // nsISocketTransportService.idl
59 const kNetTimeout = 2152398862; // nsISocketTransportService.idl
60 const kNoConnectionOrTimeout = 2152398878;
61 const kPortAccessNotAllowed = 2152398867; // netCore.h
62 const kOffline = 2152398865; // netCore.h
63 const kDiskFull = 2152857610;
64 const kNoDeviceSpace = 2152857616;
65 const kNameTooLong = 2152857617;
66 const kAccessDenied = 2152857621;
67
68 // These are more errors that I don't think we encounter during publishing,
69 // so we don't have error strings yet. Let's keep them here for future reference
70 //const kUnrecognizedPath = 2152857601;
71 //const kUnresolvableSymlink = 2152857602;
72 //const kUnknownType = 2152857604;
73 //const kDestinationNotDir = 2152857605;
74 //const kTargetDoesNotExist = 2152857606;
75 //const kAlreadyExists = 2152857608;
76 //const kInvalidPath = 2152857609;
77 //const kNotDirectory = 2152857612;
78 //const kIsDirectory = 2152857613;
79 //const kIsLocked = 2152857614;
80 //const kTooBig = 2152857615;
81 //const kReadOnly = 2152857619;
82 //const kDirectoryNotEmpty = 2152857620;
83 //const kErrorBindingRedirected = 2152398851;
84 //const kAlreadyConnected = 2152398859; // in netCore.h
85 //const kInProgress = 2152398863; // netCore.h
86 //const kNoContent = 2152398865; // netCore.h
87 //const kUnknownProtocol = 2152398866 // netCore.h
88 //const kFtpLogin = 2152398869; // ftpCore.h
89 //const kFtpCWD = 2152398870; // ftpCore.h
90 //const kFtpPasv = 2152398871; // ftpCore.h
91 //const kFtpPwd = 2152398872; // ftpCore.h
92
93
Startup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
94 function Startup()
95 {
96 gPublishData = window.arguments[0];
97 if (!gPublishData)
98 {
99 dump("No publish data!\n");
100 window.close();
101 return;
102 }
103
104 gDialog.FileList = document.getElementById("FileList");
105 gDialog.FinalStatusMessage = document.getElementById("FinalStatusMessage");
106 gDialog.StatusMessage = document.getElementById("StatusMessage");
107 gDialog.KeepOpen = document.getElementById("KeepOpen");
108 gDialog.Close = document.documentElement.getButton("cancel");
109
110 SetWindowLocation();
111 var title = GetDocumentTitle();
112 if (!title)
113 title = "("+GetString("untitled")+")";
114 document.title = GetString("PublishProgressCaption").replace(/%title%/, title);
115
116 document.getElementById("PublishToSite").value =
117 GetString("PublishToSite").replace(/%title%/, TruncateStringAtWordEnd(gPublishData.siteName, 25));
118
119 // Show publishing destination URL
120 document.getElementById("PublishUrl").value = gPublishData.publishUrl;
121
122 // Show subdirectories only if not empty
123 if (gPublishData.docDir || gPublishData.otherDir)
124 {
125 if (gPublishData.docDir)
126 document.getElementById("docDir").value = gPublishData.docDir;
127 else
128 document.getElementById("DocSubdir").hidden = true;
129
130 if (gPublishData.publishOtherFiles && gPublishData.otherDir)
131 document.getElementById("otherDir").value = gPublishData.otherDir;
132 else
133 document.getElementById("OtherSubdir").hidden = true;
134 }
135 else
136 document.getElementById("Subdirectories").hidden = true;
137
138 // Add the document to the "publish to" list as quick as possible!
139 SetProgressStatus(gPublishData.filename, "busy");
140
141 if (gPublishData.publishOtherFiles)
142 {
143 // When publishing images as well, expand list to show more items
144 gDialog.FileList.setAttribute("rows", 5);
145 window.sizeToContent();
146 }
147
148 // Now that dialog is initialized, we can start publishing
149 gPersistObj = window.opener.StartPublishing();
150 }
151
152 // this function is to be used when we cancel persist's saving
153 // since not all messages will be returned to us if we cancel
154 // this function changes status for all non-done/non-failure to failure
SetProgressStatusCancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
155 function SetProgressStatusCancel()
156 {
157 var listitems = document.getElementsByTagName("listitem");
158 if (!listitems)
159 return;
160
161 for (var i=0; i < listitems.length; i++)
162 {
163 var attr = listitems[i].getAttribute("progress");
164 if (attr != "done" && attr != "failed")
165 listitems[i].setAttribute("progress", "failed");
166 }
167 }
168
169 // Add filename to list of files to publish
170 // or set status for file already in the list
171 // Returns true if file was in the list
SetProgressStatus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
172 function SetProgressStatus(filename, status)
173 {
174 if (!filename)
175 return false;
176
177 if (!status)
178 status = "busy";
179
180 // Just set attribute for status icon
181 // if we already have this filename
182 var listitems = document.getElementsByTagName("listitem");
183 if (listitems)
184 {
185 for (var i=0; i < listitems.length; i++)
186 {
187 if (listitems[i].getAttribute("label") == filename)
188 {
189 listitems[i].setAttribute("progress", status);
190 return true;
191 }
192 }
193 }
194 // We're adding a new file item to list
195 gTotalFileCount++;
196
197 var listitem = document.createElementNS(XUL_NS, "listitem");
198 if (listitem)
199 {
200 listitem.setAttribute("class", "listitem-iconic progressitem");
201 // This triggers CSS to show icon for each status state
202 listitem.setAttribute("progress", status);
203 listitem.setAttribute("label", filename);
204 gDialog.FileList.appendChild(listitem);
205 }
206 return false;
207 }
208
SetProgressFinished
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
209 function SetProgressFinished(filename, networkStatus)
210 {
211 var abortPublishing = false;
212 if (filename)
213 {
214 var status = networkStatus ? "failed" : "done";
215 if (networkStatus == 0)
216 gSucceededCount++;
217
218 SetProgressStatus(filename, status);
219 }
220
221 if (networkStatus != 0) // Error condition
222 {
223 // We abort on all errors except if image file was not found
224 abortPublishing = networkStatus != kFileNotFound;
225
226 // Mark all remaining files as "failed"
227 if (abortPublishing)
228 {
229 gPublishingFailed = true;
230 SetProgressStatusCancel();
231 gDialog.FinalStatusMessage.value = GetString("PublishFailed");
232 }
233
234 switch (networkStatus)
235 {
236 case kFileNotFound:
237 gFileNotFound = true;
238 if (filename)
239 gStatusMessage = GetString("FileNotFound").replace(/%file%/, filename);
240 break;
241 case kNetReset:
242 // We get this when subdir doesn't exist AND
243 // if filename used is same as an existing subdir
244 var dir = (gPublishData.filename == filename) ?
245 gPublishData.docDir : gPublishData.otherDir;
246
247 if (dir)
248 {
249 // This is the ambiguous case when we can't tell if subdir or filename is bad
250 // Remove terminal "/" from dir string and insert into message
251 gStatusMessage = GetString("SubdirDoesNotExist").replace(/%dir%/, dir.slice(0, dir.length-1));
252 gStatusMessage = gStatusMessage.replace(/%file%/, filename);
253
254 // Remove directory from saved prefs
255 // XXX Note that if subdir is good,
256 // but filename = next level subdirectory name,
257 // we really shouldn't remove subdirectory,
258 // but it's impossible to differentiate this case!
259 RemovePublishSubdirectoryFromPrefs(gPublishData, dir);
260 }
261 else if (filename)
262 gStatusMessage = GetString("FilenameIsSubdir").replace(/%file%/, filename);
263
264 break;
265 case kNotConnected:
266 case kConnectionRefused:
267 case kNetTimeout:
268 case kNoConnectionOrTimeout:
269 case kPortAccessNotAllowed:
270 gStatusMessage = GetString("ServerNotAvailable");
271 break;
272 case kOffline:
273 gStatusMessage = GetString("Offline");
274 break;
275 case kDiskFull:
276 case kNoDeviceSpace:
277 if (filename)
278 gStatusMessage = GetString("DiskFull").replace(/%file%/, filename);
279 break;
280 case kNameTooLong:
281 if (filename)
282 gStatusMessage = GetString("NameTooLong").replace(/%file%/, filename);
283 break;
284 case kAccessDenied:
285 if (filename)
286 gStatusMessage = GetString("AccessDenied").replace(/%file%/, filename);
287 break;
288 case kUnknownType:
289 default:
290 gStatusMessage = GetString("UnknownPublishError")
291 break;
292 }
293 }
294 else if (!filename)
295 {
296 gFinished = true;
297
298 document.documentElement.setAttribute("buttonlabelcancel",
299 document.documentElement.getAttribute("buttonlabelclose"));
300
301 if (!gStatusMessage)
302 gStatusMessage = GetString(gPublishingFailed ? "UnknownPublishError" : "AllFilesPublished");
303
304 // Now allow "Enter/Return" key to close the dialog
305 AllowDefaultButton();
306
307 if (gPublishingFailed || gFileNotFound)
308 {
309 // Show "Troubleshooting" button to help solving problems
310 // and key for successful / failed files
311 document.getElementById("failureBox").hidden = false;
312 }
313 }
314
315 if (gStatusMessage)
316 SetStatusMessage(gStatusMessage);
317 }
318
CheckKeepOpen
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
319 function CheckKeepOpen()
320 {
321 if (gTimerID)
322 {
323 clearTimeout(gTimerID);
324 gTimerID = null;
325 }
326 }
327
onClose
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
328 function onClose()
329 {
330 if (!gFinished)
331 {
332 const nsIPromptService = Components.interfaces.nsIPromptService;
333 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
334 .getService(nsIPromptService);
335 const buttonFlags = (nsIPromptService.BUTTON_TITLE_IS_STRING *
336 nsIPromptService.BUTTON_POS_0) +
337 (nsIPromptService.BUTTON_TITLE_CANCEL *
338 nsIPromptService.BUTTON_POS_1);
339 var button = promptService.confirmEx(window,
340 GetString("CancelPublishTitle"),
341 GetString("CancelPublishMessage"),
342 buttonFlags,
343 GetString("CancelPublishContinue"),
344 null, null, null, {});
345 if (button == 0)
346 return false;
347 }
348
349 if (gTimerID)
350 {
351 clearTimeout(gTimerID);
352 gTimerID = null;
353 }
354
355 if (!gFinished && gPersistObj)
356 {
357 try {
358 gPersistObj.cancelSave();
359 } catch (e) {}
360 }
361 SaveWindowLocation();
362
363 // Tell caller so they can cleanup and restore editability
364 window.opener.FinishPublishing();
365 return true;
366 }
367
AllowDefaultButton
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
368 function AllowDefaultButton()
369 {
370 gDialog.Close.setAttribute("default","true");
371 gAllowEnterKey = true;
372 }
373
onEnterKey
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
374 function onEnterKey()
375 {
376 if (gAllowEnterKey)
377 return CloseDialog();
378
379 return false;
380 }
381
RequestCloseDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
382 function RequestCloseDialog()
383 {
384 // Finish progress messages, settings buttons etc.
385 SetProgressFinished(null, 0);
386
387 if (!gDialog.KeepOpen.checked)
388 {
389 // Leave window open a minimum amount of time
390 gTimerID = setTimeout("CloseDialog();", 3000);
391 }
392
393 // Set "completed" message if we succeeded
394 // (Some image files may have failed,
395 // but we don't abort publishing for that)
396 if (!gPublishingFailed)
397 {
398 gDialog.FinalStatusMessage.value = GetString("PublishCompleted");
399 if (gFileNotFound && gTotalFileCount-gSucceededCount)
400 {
401 // Show number of files that failed to upload
402 gStatusMessage =
403 (GetString("FailedFileMsg").replace(/%x%/,(gTotalFileCount-gSucceededCount)))
404 .replace(/%total%/,gTotalFileCount);
405
406 SetStatusMessage(gStatusMessage);
407 }
408 }
409 }
410
SetStatusMessage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
411 function SetStatusMessage(message)
412 {
413 // Status message is a child of <description> element
414 // so text can wrap to multiple lines if necessary
415 if (gDialog.StatusMessage.firstChild)
416 {
417 gDialog.StatusMessage.firstChild.data = message;
418 }
419 else
420 {
421 var textNode = document.createTextNode(message);
422 if (textNode)
423 gDialog.StatusMessage.appendChild(textNode);
424 }
425 window.sizeToContent();
426 }
427
CloseDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
428 function CloseDialog()
429 {
430 SaveWindowLocation();
431 window.opener.FinishPublishing();
432 try {
433 window.close();
434 } catch (e) {}
435 }