116
/* Shows or hides the "upload panel" in the side panel.
117
* toshow is true for showing, false for hiding.
119
function show_uploadpanel(toshow)
121
document.getElementById("uploadpanel").setAttribute("style",
122
"display: " + (toshow ? "auto" : "none") + ";");
126
/* Called when a form upload comes back (from an iframe).
127
* Refreshes the page.
129
function upload_callback()
131
/* This has a pretty nasty hack, which happens to work.
132
* upload_callback is set as the "onload" callback for the iframe which
133
* receives the response from the server for uploading a file.
134
* This means it gets called twice. Once when initialising the iframe, and
135
* a second time when the actual response comes back.
136
* All we want to do is call navigate to refresh the page. But we CAN'T do
137
* that on the first load or it will just go into an infinite cycle of
138
* refreshing. We need to refresh the page ONLY on the second refresh.
139
* upload_callback_count is reset to 0 just before the iframe is created.
141
upload_callback_count++;
142
if (upload_callback_count == 2)
144
navigate(current_path);
145
/* Keep upload panel open */
146
show_uploadpanel(true);
116
150
/** END ACTIONS **/
118
152
/** Updates the side-panel. Expects selected_files reflects the current
337
372
"Paste the copied or cut files to the current directory", null,
338
373
"return action_paste()");
339
374
sidepanel.appendChild(p);
375
p = dom_make_link_elem("p", "Upload",
376
"Upload a file to the current directory", null,
377
"return show_uploadpanel(true)");
378
sidepanel.appendChild(p);
379
/* The "Upload" button expands the following panel with upload tools */
380
/* This panel has a form for submitting the file to, and an iframe to load
381
* the target page in (this avoids the entire page being refreshed) */
382
div = document.createElement("div");
383
div.setAttribute("id", "uploadpanel");
384
/* This deliberately hides the upload panel whenever the selection
385
* changes. It can be re-shown by clicking "upload". */
386
div.setAttribute("style", "display: none;");
387
sidepanel.appendChild(div);
388
p = dom_make_text_elem("h3", "Upload File");
390
var form = document.createElement("form");
391
form.setAttribute("method", "POST");
392
form.setAttribute("enctype", "multipart/form-data");
393
form.setAttribute("action", app_path("fileservice", current_path));
394
form.setAttribute("target", "upload_iframe");
395
div.appendChild(form);
397
input = document.createElement("input");
398
input.setAttribute("type", "hidden");
399
input.setAttribute("name", "action");
400
input.setAttribute("value", "putfiles");
401
form.appendChild(input);
403
input = document.createElement("input");
404
input.setAttribute("type", "hidden");
405
input.setAttribute("name", "path");
406
input.setAttribute("value", "");
407
form.appendChild(input);
409
p = document.createElement("p");
411
input = document.createElement("input");
412
input.setAttribute("type", "file");
413
input.setAttribute("name", "data");
414
p.appendChild(input);
416
p = document.createElement("p");
418
input = document.createElement("input");
419
input.setAttribute("type", "button");
420
input.setAttribute("value", "Hide");
421
input.setAttribute("onclick", "show_uploadpanel(false)");
422
p.appendChild(input);
423
p.appendChild(document.createTextNode(" "));
424
input = document.createElement("input");
425
input.setAttribute("type", "submit");
426
input.setAttribute("value", "Send");
427
p.appendChild(input);
429
/* Now we create an invisible iframe which will receive the upload.
430
* The form submits to fileservice, loading the result into this iframe
431
* instead of the whole browser window (this is an alternative to Ajax,
432
* since Ajax doesn't allow reading the file from the user's disk).
433
* Note this iframe's id is the same as the form's target.
435
var upload_iframe = document.createElement("iframe");
436
upload_iframe.setAttribute("id", "upload_iframe");
437
upload_iframe.setAttribute("name", "upload_iframe");
438
upload_iframe.setAttribute("style", "display: none;");
439
/* When we get a callback, simply cause a nav to the current path, so we
440
* update the directory listing. */
441
upload_callback_count = 0; /* See upload_callback */
442
upload_iframe.setAttribute("onload", "upload_callback()");
443
div.appendChild(upload_iframe);
444
/* END Upload panel */
341
446
if (under_subversion)