409
424
div.appendChild(par2);
427
function update_actions()
430
var numsel = selected_files.length;
435
/* Display information about the current directory instead */
436
filename = path_basename(current_path);
439
else if (numsel == 1)
441
filename = selected_files[0];
442
file = file_listing[filename];
445
/* Update each action node in the topbar.
446
* This includes enabling/disabling actions as appropriate, and
447
* setting href/onclick attributes. */
451
/* Available if exactly one file is selected */
452
var open = document.getElementById("act_open");
455
open.setAttribute("class", "choice");
457
open.setAttribute("title",
458
"Navigate to this directory in the file browser");
460
open.setAttribute("title",
461
"Edit or view this file");
462
open.setAttribute("href", app_path(this_app, current_path, filename));
466
open.setAttribute("class", "disabled");
467
open.removeAttribute("title");
468
open.removeAttribute("href");
472
/* Available if exactly one file is selected,
473
* and only if this is a file, not a directory */
474
var serve = document.getElementById("act_serve");
475
if (numsel == 1 && !file.isdir)
477
serve.setAttribute("class", "choice");
478
serve.setAttribute("href",
479
app_path(serve_app, current_path, filename));
483
serve.setAttribute("class", "disabled");
484
serve.removeAttribute("href");
488
/* Available if exactly one file is selected,
489
* and it is a Python file.
495
* If 0 files selected, download the current file or directory as a ZIP.
496
* If 1 directory selected, download it as a ZIP.
497
* If 1 non-directory selected, download it.
498
* If >1 files selected, download them all as a ZIP.
500
var download = document.getElementById("act_download");
505
download.setAttribute("href",
506
app_path(download_app, current_path));
508
download.setAttribute("title",
509
"Download the current directory as a ZIP file");
511
download.setAttribute("title",
512
"Download the current file");
516
download.setAttribute("href",
517
app_path(download_app, current_path, filename));
519
download.setAttribute("title",
520
"Download the selected directory as a ZIP file");
522
download.setAttribute("title",
523
"Download the selected file");
528
/* Make a query string with all the files to download */
529
var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
530
for (var i=0; i<numsel; i++)
531
dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
532
dlpath = dlpath.substr(0, dlpath.length-1);
533
download.setAttribute("href", dlpath);
534
download.setAttribute("title",
535
"Download the selected files as a ZIP file");
538
/* Refresh - No changes required */
540
/* Publish and Submit */
541
/* If this directory is under subversion and selected/unselected file is a
543
var publish = document.getElementById("act_publish");
544
var submit = document.getElementById("act_submit");
545
if (numsel <= 1 && file.isdir)
547
/* TODO: Work out of file is svn'd */
548
/* TODO: If this dir is already published, call it "Unpublish" */
549
publish.setAttribute("class", "choice");
550
publish.removeAttribute("disabled");
551
submit.setAttribute("class", "choice");
552
submit.removeAttribute("disabled");
556
publish.setAttribute("class", "disabled");
557
publish.setAttribute("disabled", "disabled");
558
submit.setAttribute("class", "disabled");
559
submit.setAttribute("disabled", "disabled");
563
/* If exactly 1 non-directory file is selected/opened, and its parent
564
* directory is published.
566
var share = document.getElementById("act_share");
567
if (numsel <= 1 && !file.isdir)
569
/* TODO: Work out if parent dir is published */
570
share.setAttribute("class", "choice");
571
share.removeAttribute("disabled");
575
share.setAttribute("class", "disabled");
576
share.setAttribute("disabled", "disabled");
580
/* If exactly 1 file is selected */
581
var rename = document.getElementById("act_rename");
584
rename.setAttribute("class", "choice");
585
rename.removeAttribute("disabled");
589
rename.setAttribute("class", "disabled");
590
rename.setAttribute("disabled", "disabled");
593
/* Delete, cut, copy */
594
/* If >= 1 file is selected */
595
var act_delete = document.getElementById("act_delete");
596
var cut = document.getElementById("act_cut");
597
var copy = document.getElementById("act_copy");
600
act_delete.setAttribute("class", "choice");
601
act_delete.removeAttribute("disabled");
602
cut.setAttribute("class", "choice");
603
cut.removeAttribute("disabled");
604
copy.setAttribute("class", "choice");
605
copy.removeAttribute("disabled");
609
act_delete.setAttribute("class", "disabled");
610
act_delete.setAttribute("disabled", "disabled");
611
cut.setAttribute("class", "disabled");
612
cut.setAttribute("disabled", "disabled");
613
copy.setAttribute("class", "disabled");
614
copy.setAttribute("disabled", "disabled");
617
/* Paste, new file, new directory, upload */
618
/* Always enabled (assuming this is a directory) */
620
/* Subversion actions */
621
/* TODO: Work out when these are appropriate */
622
var svnadd = document.getElementById("act_svnadd");
623
var svnrevert = document.getElementById("act_svnrevert");
624
var svncommit = document.getElementById("act_svncommit");
627
svnadd.setAttribute("class", "choice");
628
svnadd.removeAttribute("disabled");
629
svnrevert.setAttribute("class", "choice");
630
svnrevert.removeAttribute("disabled");
631
svncommit.setAttribute("class", "choice");
632
svncommit.removeAttribute("disabled");
638
/* Unrefactored Code */
646
/* Publish/unpublish */
647
if (selected_files.length == 0)
651
if ("published" in file && file.published)
653
p = dom_make_link_elem("p", "Unpublish",
654
"Make it so this directory cannot be seen by anyone but you",
656
"return action_unpublish(" + repr(path) + ")");
657
sidepanel.appendChild(p);
661
p = dom_make_link_elem("p", "Publish",
662
"Make it so this directory can be seen by anyone on the web",
664
"return action_publish(" + repr(path) + ")");
665
sidepanel.appendChild(p);
669
var handler_type = null;
671
handler_type = get_handler_type(file.type);
672
/* Action: Use the "files" / "edit" app */
674
if (selected_files.length == 1)
676
/* Don't have "Browse" if this is the current dir */
678
p = dom_make_link_elem("p", "Browse",
679
"Navigate to this directory in the file browser",
680
app_path(this_app, current_path, filename));
681
else if (handler_type == "text")
682
p = dom_make_link_elem("p", "Edit", "Edit this file",
683
app_path(edit_app, current_path, filename));
685
p = dom_make_link_elem("p", "Browse",
686
"View this file in the file browser",
687
app_path(this_app, current_path, filename));
688
sidepanel.appendChild(p);
691
/* Action: Use the "serve" app */
692
/* TODO: Figure out if this file is executable,
693
* and change the link to "Run" */
695
if (file.isdir || handler_type == "binary") {}
697
p = dom_make_link_elem("p", "View",
699
app_path(serve_app, current_path, filename));
701
sidepanel.appendChild(p);
703
/* Action: Use the "download" app */
705
if (selected_files.length == 0)
706
path = app_path(download_app, current_path);
708
path = app_path(download_app, current_path, filename);
710
p = dom_make_link_elem("p", "Download as zip",
711
"Download this directory as a ZIP file", path);
713
p = dom_make_link_elem("p", "Download",
714
"Download this file to your computer", path);
716
sidepanel.appendChild(p);
718
if (selected_files.length > 0)
719
{ /* Can't rename if we're in it */
720
p = dom_make_link_elem("p", "Rename",
721
"Change the name of this file", null,
722
"return action_rename(" + repr(filename) + ")");
723
sidepanel.appendChild(p);
728
path = urlencode_path(app_path(download_app, current_path)) + "?";
729
for (var i=0; i<selected_files.length; i++)
730
path += "path=" + encodeURIComponent(selected_files[i]) + "&";
731
path = path.substr(0, path.length-1);
732
/* Multiple files selected */
733
p = dom_make_link_elem("p", "Download as zip",
734
"Download the selected files as a ZIP file", path, null, true);
735
sidepanel.appendChild(p);
739
if (selected_files.length > 0)
741
p = dom_make_link_elem("p", "Delete",
742
"Delete the selected files", null,
743
"return action_remove(selected_files)");
744
sidepanel.appendChild(p);
745
p = dom_make_link_elem("p", "Cut",
746
"Prepare to move the selected files to another directory", null,
747
"return action_cut(selected_files)");
748
sidepanel.appendChild(p);
749
p = dom_make_link_elem("p", "Copy",
750
"Prepare to copy the selected files to another directory", null,
751
"return action_copy(selected_files)");
752
sidepanel.appendChild(p);
754
p = dom_make_link_elem("p", "Paste",
755
"Paste the copied or cut files to the current directory", null,
756
"return action_paste()");
757
sidepanel.appendChild(p);
758
p = dom_make_link_elem("p", "Make Directory",
759
"Make a new subdirectory in the current directory", null,
760
"return action_mkdir()");
761
sidepanel.appendChild(p);
762
p = dom_make_link_elem("p", "Upload",
763
"Upload a file to the current directory", null,
764
"return show_uploadpanel()");
765
sidepanel.appendChild(p);
766
/* The "Upload" button expands the following panel with upload tools */
767
/* This panel has a form for submitting the file to, and an iframe to load
768
* the target page in (this avoids the entire page being refreshed) */
769
div = document.createElement("div");
770
div.setAttribute("id", "uploadpanel");
771
/* This deliberately hides the upload panel whenever the selection
772
* changes. It can be re-shown by clicking "upload". */
773
div.setAttribute("style", "display: none;");
774
sidepanel.appendChild(div);
775
p = dom_make_text_elem("h3", "Upload File");
777
var form = document.createElement("form");
778
form.setAttribute("method", "POST");
779
form.setAttribute("enctype", "multipart/form-data");
780
form.setAttribute("action", app_path("fileservice", current_path));
781
form.setAttribute("target", "upload_iframe");
782
div.appendChild(form);
784
input = document.createElement("input");
785
input.setAttribute("type", "hidden");
786
input.setAttribute("name", "action");
787
input.setAttribute("value", "putfiles");
788
form.appendChild(input);
790
input = document.createElement("input");
791
input.setAttribute("type", "hidden");
792
input.setAttribute("name", "path");
793
input.setAttribute("value", "");
794
form.appendChild(input);
796
p = document.createElement("p");
798
input = document.createElement("input");
799
input.setAttribute("type", "file");
800
input.setAttribute("name", "data");
801
p.appendChild(input);
803
p = document.createElement("p");
805
input = document.createElement("input");
806
input.setAttribute("type", "checkbox");
807
input.setAttribute("name", "unpack");
808
input.setAttribute("value", "true");
809
input.setAttribute("checked", "on");
810
p.appendChild(input);
811
p.appendChild(document.createTextNode(" Unpack zip file"));
813
p = document.createElement("p");
815
input = document.createElement("input");
816
input.setAttribute("type", "button");
817
input.setAttribute("value", "Hide");
818
input.setAttribute("onclick", "show_uploadpanel(false)");
819
p.appendChild(input);
820
p.appendChild(document.createTextNode(" "));
821
input = document.createElement("input");
822
input.setAttribute("type", "submit");
823
input.setAttribute("value", "Send");
824
p.appendChild(input);
826
/* Now we create an invisible iframe which will receive the upload.
827
* The form submits to fileservice, loading the result into this iframe
828
* instead of the whole browser window (this is an alternative to Ajax,
829
* since Ajax doesn't allow reading the file from the user's disk).
830
* Note this iframe's id is the same as the form's target.
832
var upload_iframe = document.createElement("iframe");
833
upload_iframe.setAttribute("id", "upload_iframe");
834
upload_iframe.setAttribute("name", "upload_iframe");
835
upload_iframe.setAttribute("style", "display: none;");
836
/* When we get a callback, simply cause a nav to the current path, so we
837
* update the directory listing. */
838
upload_callback_count = 0; /* See upload_callback */
839
upload_iframe.setAttribute("onload", "upload_callback()");
840
div.appendChild(upload_iframe);
841
/* END Upload panel */
843
if (under_subversion)
845
/* TODO: Only show relevant links */
846
p = dom_make_text_elem("h3", "Subversion");
847
sidepanel.appendChild(p);
849
/* TODO: if any selected files are unversioned */
850
p = dom_make_link_elem("p", "Add",
851
"Schedule the selected temporary files to be added permanently",
853
"return action_add(selected_files)");
854
sidepanel.appendChild(p);
855
p = dom_make_link_elem("p", "Revert",
856
"Restore the selected files back to their last committed state",
858
"return action_revert(selected_files)");
859
sidepanel.appendChild(p);
861
p = dom_make_link_elem("p", "Commit",
862
"Commit any changes to the permanent repository",
864
"return action_commit(selected_files)");
865
sidepanel.appendChild(p);
870
/** Event handler for when an item of the "More actions..." dropdown box is
871
* selected. Performs the selected action. */
872
function handle_moreactions()
874
var moreactions = document.getElementById("moreactions");
875
if (moreactions.value == "top")
877
var selectedaction = moreactions.value;
878
/* Reset to "More actions..." */
879
moreactions.selectedIndex = 0;
881
/* Now handle the selected action */
882
alert("Action: " + selectedaction);
412
886
/** Called when the page loads initially.
414
888
window.onload = function()