266
var err = document.createElement("div");
267
var p = dom_make_text_elem("p", "Error: "
268
+ "There was an unexpected server error processing "
269
+ "the selected command.");
271
p = dom_make_text_elem("p", "If the problem persists, please "
272
+ "contact the system administrator.")
274
p = document.createElement("p");
275
var refresh = document.createElement("input");
276
refresh.setAttribute("type", "button");
277
refresh.setAttribute("value", "Back to file view");
278
refresh.setAttribute("onclick", "refresh()");
279
p.appendChild(refresh);
285
var err = document.createElement("div");
286
var p = dom_make_text_elem("p", "Error: "
287
+ "There was an unexpected server error retrieving "
288
+ "the requested file or directory.");
290
p = dom_make_text_elem("p", "If the problem persists, please "
291
+ "contact the system administrator.")
247
handle_error("The server returned an invalid directory listing");
297
250
/* Get "." out, it's special */
298
251
current_file = file_listing["."]; /* Global */
299
252
delete file_listing["."];
301
if ('revision' in listing)
303
current_revision = listing.revision;
306
254
/* Check if this is a directory listing or file contents */
307
255
var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
311
home_listing(listing, subjects, path);
258
handle_dir_listing(path, listing);
426
351
/*** HANDLERS for different types of responses (such as dir listing, file,
430
* message may either be a string, or a DOM node, which will be placed inside
433
354
function handle_error(message)
435
356
var files = document.getElementById("filesbody");
437
if (typeof(message) == "string")
439
txt_elem = dom_make_text_elem("div", "Error: "
440
+ message.toString() + ".")
444
/* Assume message is a DOM node */
445
txt_elem = document.createElement("div");
446
txt_elem.appendChild(message);
357
var txt_elem = dom_make_text_elem("div", "Error: "
358
+ message.toString() + ".")
448
359
txt_elem.setAttribute("class", "padding error");
449
360
files.appendChild(txt_elem);
452
/** Given a path, filename and optional revision, returns a URL to open that
453
* revision of that file.
455
function build_revision_url(path, filename, revision)
457
bits = {'path': app_path(this_app, path, filename)};
458
if (current_revision)
460
bits['query_string'] = 'r=' + revision;
462
return build_url(bits);
465
363
/** Given a mime type, returns the path to the icon.
466
364
* \param type String, Mime type.
467
365
* \param sizelarge Boolean, optional.
613
/* Available if zero or one files are selected,
471
/* Available if exactly one file is selected,
614
472
* and only if this is a file, not a directory */
615
473
var serve = document.getElementById("act_serve");
616
if (numsel <= 1 && !file.isdir && current_file.svnstatus != 'revision')
474
if (numsel == 1 && !file.isdir)
618
476
serve.setAttribute("class", "choice");
619
serve.setAttribute("onclick",
620
"return maybe_save('The last saved version will be served.')");
622
serve.setAttribute("href",
623
app_path(serve_app, current_path));
625
serve.setAttribute("href",
626
app_path(serve_app, current_path, filename));
477
serve.setAttribute("href",
478
app_path(serve_app, current_path, filename));
630
482
serve.setAttribute("class", "disabled");
631
483
serve.removeAttribute("href");
632
serve.removeAttribute("onclick");
636
487
/* Available if exactly one file is selected,
637
488
* and it is a Python file.
639
var run = document.getElementById("act_run");
641
if (numsel <= 1 && !file.isdir && file.type == "text/x-python"
642
&& current_file.svnstatus != 'revision')
646
// In the edit window
647
var localpath = path_join('/home', current_path);
651
// In the browser window
652
var localpath = path_join('/home', current_path, filename);
654
run.setAttribute("class", "choice");
655
run.setAttribute("onclick", "runfile('" + localpath + "')");
659
run.setAttribute("class", "disabled");
660
run.removeAttribute("onclick");
664
/* Always available for current files.
665
494
* If 0 files selected, download the current file or directory as a ZIP.
666
495
* If 1 directory selected, download it as a ZIP.
667
496
* If 1 non-directory selected, download it.
668
497
* If >1 files selected, download them all as a ZIP.
670
499
var download = document.getElementById("act_download");
671
if (current_file.svnstatus == 'revision')
673
download.setAttribute("class", "disabled");
674
download.removeAttribute("onclick");
676
else if (numsel <= 1)
678
download.setAttribute("class", "choice")
681
504
download.setAttribute("href",
720
542
var publish = document.getElementById("act_publish");
721
543
var submit = document.getElementById("act_submit");
722
var pubcond = numsel <= 1 && file.isdir;
725
/* If this dir is already published, call it "Unpublish" */
728
publish.setAttribute("value", "unpublish");
729
publish.setAttribute("title" ,"Make it so this directory "
730
+ "can not be seen by anyone on the web");
731
publish.firstChild.nodeValue = "Unpublish";
733
publish.setAttribute("value", "publish");
734
publish.setAttribute("title","Make it so this directory "
735
+ "can be seen by anyone on the web");
736
publish.firstChild.nodeValue = "Publish";
739
set_action_state(["publish", "submit"], pubcond);
544
if (numsel <= 1 && file.isdir)
546
/* TODO: Work out of file is svn'd */
547
/* TODO: If this dir is already published, call it "Unpublish" */
548
publish.setAttribute("class", "choice");
549
publish.removeAttribute("disabled");
550
submit.setAttribute("class", "choice");
551
submit.removeAttribute("disabled");
555
publish.setAttribute("class", "disabled");
556
publish.setAttribute("disabled", "disabled");
557
submit.setAttribute("class", "disabled");
558
submit.setAttribute("disabled", "disabled");
742
/* If exactly 1 non-directory file is selected, and its parent
562
/* If exactly 1 non-directory file is selected/opened, and its parent
743
563
* directory is published.
745
set_action_state("share", numsel == 1 && !file.isdir &&
746
current_file.published);
565
var share = document.getElementById("act_share");
566
if (numsel <= 1 && !file.isdir)
568
/* TODO: Work out if parent dir is published */
569
share.setAttribute("class", "choice");
570
share.removeAttribute("disabled");
574
share.setAttribute("class", "disabled");
575
share.setAttribute("disabled", "disabled");
749
579
/* If exactly 1 file is selected */
750
set_action_state("rename", numsel == 1);
580
var rename = document.getElementById("act_rename");
583
rename.setAttribute("class", "choice");
584
rename.removeAttribute("disabled");
588
rename.setAttribute("class", "disabled");
589
rename.setAttribute("disabled", "disabled");
752
592
/* Delete, cut, copy */
753
593
/* If >= 1 file is selected */
754
set_action_state(["delete", "cut", "copy"], numsel >= 1);
594
var act_delete = document.getElementById("act_delete");
595
var cut = document.getElementById("act_cut");
596
var copy = document.getElementById("act_copy");
599
act_delete.setAttribute("class", "choice");
600
act_delete.removeAttribute("disabled");
601
cut.setAttribute("class", "choice");
602
cut.removeAttribute("disabled");
603
copy.setAttribute("class", "choice");
604
copy.removeAttribute("disabled");
608
act_delete.setAttribute("class", "disabled");
609
act_delete.setAttribute("disabled", "disabled");
610
cut.setAttribute("class", "disabled");
611
cut.setAttribute("disabled", "disabled");
612
copy.setAttribute("class", "disabled");
613
copy.setAttribute("disabled", "disabled");
756
616
/* Paste, new file, new directory, upload */
757
/* Disable if the current file is not a directory */
758
set_action_state(["paste", "newfile", "mkdir", "upload"], current_file.isdir);
617
/* Always enabled (assuming this is a directory) */
760
619
/* Subversion actions */
761
/* These are only useful if we are in a versioned directory and have some
763
set_action_state(["svnadd"], numsel >= 1 && current_file.svnstatus);
764
/* And these are only usefull is ALL the selected files are versioned */
765
set_action_state(["svnremove", "svnrevert", "svncommit", "svncopy",
766
"svncut"], numsel >= 1 && current_file.svnstatus && svn_selection);
768
/* Diff, log and update only support one path at the moment, so we must
769
* have 0 or 1 versioned files selected. If 0, the directory must be
771
single_versioned_path = (
773
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
774
(numsel == 0 && (svnst = current_file.svnstatus))
775
) && svnst != "unversioned");
776
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
778
/* We can resolve if we have a file selected and it is conflicted. */
779
set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
781
/* Log should be available for revisions as well. */
782
set_action_state("svnlog", single_versioned_path, true);
784
single_ivle_versioned_path = (
786
(numsel == 1 && (stat = file_listing[selected_files[0]])) ||
787
(numsel == 0 && (stat = current_file))
788
) && stat.svnstatus != "unversioned"
790
&& stat.svnurl.substr(0, svn_base.length) == svn_base);
791
set_action_state(["submit"], single_ivle_versioned_path);
793
/* There is currently nothing on the More Actions menu of use
794
* when the current file is not a directory. Hence, just remove
796
* (This makes some of the above decisions somewhat redundant).
797
* We also take this opportunity to show the appropriate actions2
798
* bar for this path. It should either be a save or upload widget.
800
if (current_file.isdir)
802
var actions2_directory = document.getElementById("actions2_directory");
803
actions2_directory.setAttribute("style", "display: inline;");
804
var moreactions = document.getElementById("moreactions_area");
805
moreactions.setAttribute("style", "display: inline;");
809
var actions2_file = document.getElementById("actions2_file");
810
actions2_file.setAttribute("style", "display: inline;");
620
/* TODO: Work out when these are appropriate */
621
var svnadd = document.getElementById("act_svnadd");
622
var svnrevert = document.getElementById("act_svnrevert");
623
var svncommit = document.getElementById("act_svncommit");
626
svnadd.setAttribute("class", "choice");
627
svnadd.removeAttribute("disabled");
628
svnrevert.setAttribute("class", "choice");
629
svnrevert.removeAttribute("disabled");
630
svncommit.setAttribute("class", "choice");
631
svncommit.removeAttribute("disabled");