208
/* Called when a form upload comes back (from an iframe).
209
* Refreshes the page.
211
function upload_callback()
213
/* This has a pretty nasty hack, which happens to work.
214
* upload_callback is set as the "onload" callback for the iframe which
215
* receives the response from the server for uploading a file.
216
* This means it gets called twice. Once when initialising the iframe, and
217
* a second time when the actual response comes back.
218
* All we want to do is call navigate to refresh the page. But we CAN'T do
219
* that on the first load or it will just go into an infinite cycle of
220
* refreshing. We need to refresh the page ONLY on the second refresh.
221
* upload_callback_count is reset to 0 just before the iframe is created.
223
upload_callback_count++;
224
if (upload_callback_count == 2)
226
navigate(current_path);
227
/* Keep upload panel open */
228
show_uploadpanel(true);
232
208
/** END ACTIONS **/
234
210
/** Updates the side-panel AND the actions in the top-bar. Expects selected_files
342
318
+ nice_filesize(total_file_size_sel));
343
319
sidepanel.appendChild(p);
346
/* TEMPORARY: Move to top bar */
347
/* The "Upload" button expands the following panel with upload tools */
348
/* This panel has a form for submitting the file to, and an iframe to load
349
* the target page in (this avoids the entire page being refreshed) */
350
div = document.createElement("div");
351
div.setAttribute("id", "uploadpanel");
352
/* This deliberately hides the upload panel whenever the selection
353
* changes. It can be re-shown by clicking "upload". */
354
div.setAttribute("style", "display: none;");
355
sidepanel.appendChild(div);
356
p = dom_make_text_elem("h3", "Upload File");
358
var form = document.createElement("form");
359
form.setAttribute("method", "POST");
360
form.setAttribute("enctype", "multipart/form-data");
361
form.setAttribute("action", app_path("fileservice", current_path));
362
form.setAttribute("target", "upload_iframe");
363
div.appendChild(form);
365
input = document.createElement("input");
366
input.setAttribute("type", "hidden");
367
input.setAttribute("name", "action");
368
input.setAttribute("value", "putfiles");
369
form.appendChild(input);
371
input = document.createElement("input");
372
input.setAttribute("type", "hidden");
373
input.setAttribute("name", "path");
374
input.setAttribute("value", "");
375
form.appendChild(input);
377
p = document.createElement("p");
379
input = document.createElement("input");
380
input.setAttribute("type", "file");
381
input.setAttribute("name", "data");
382
input.setAttribute("size", "10");
383
p.appendChild(input);
385
p = document.createElement("p");
387
input = document.createElement("input");
388
input.setAttribute("type", "checkbox");
389
input.setAttribute("name", "unpack");
390
input.setAttribute("value", "true");
391
input.setAttribute("checked", "on");
392
p.appendChild(input);
393
p.appendChild(document.createTextNode(" Unpack zip file"));
395
p = document.createElement("p");
397
input = document.createElement("input");
398
input.setAttribute("type", "button");
399
input.setAttribute("value", "Hide");
400
input.setAttribute("onclick", "show_uploadpanel(false)");
401
p.appendChild(input);
402
p.appendChild(document.createTextNode(" "));
403
input = document.createElement("input");
404
input.setAttribute("type", "submit");
405
input.setAttribute("value", "Send");
406
p.appendChild(input);
408
/* Now we create an invisible iframe which will receive the upload.
409
* The form submits to fileservice, loading the result into this iframe
410
* instead of the whole browser window (this is an alternative to Ajax,
411
* since Ajax doesn't allow reading the file from the user's disk).
412
* Note this iframe's id is the same as the form's target.
414
var upload_iframe = document.createElement("iframe");
415
upload_iframe.setAttribute("id", "upload_iframe");
416
upload_iframe.setAttribute("name", "upload_iframe");
417
upload_iframe.setAttribute("style", "display: none;");
418
/* When we get a callback, simply cause a nav to the current path, so we
419
* update the directory listing. */
420
upload_callback_count = 0; /* See upload_callback */
421
upload_iframe.setAttribute("onload", "upload_callback()");
422
div.appendChild(upload_iframe);
423
/* END Upload panel */
426
323
/** Updates the side-panel and status bar to reflect the current set of