247
handle_error("The server returned an invalid directory listing");
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.")
250
297
/* Get "." out, it's special */
251
298
current_file = file_listing["."]; /* Global */
252
299
delete file_listing["."];
301
if ('revision' in listing)
303
current_revision = listing.revision;
254
306
/* Check if this is a directory listing or file contents */
255
307
var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
310
setup_for_dir_listing(listing, subjects);
258
311
handle_dir_listing(path, listing);
351
421
/*** HANDLERS for different types of responses (such as dir listing, file,
425
* message may either be a string, or a DOM node, which will be placed inside
354
428
function handle_error(message)
356
430
var files = document.getElementById("filesbody");
357
var txt_elem = dom_make_text_elem("div", "Error: "
358
+ message.toString() + ".")
432
if (typeof(message) == "string")
434
txt_elem = dom_make_text_elem("div", "Error: "
435
+ message.toString() + ".")
439
/* Assume message is a DOM node */
440
txt_elem = document.createElement("div");
441
txt_elem.appendChild(message);
359
443
txt_elem.setAttribute("class", "padding error");
360
444
files.appendChild(txt_elem);
447
/** Given a path, filename and optional revision, returns a URL to open that
448
* revision of that file.
450
function build_revision_url(path, filename, revision)
452
bits = {'path': app_path(this_app, path, filename)};
453
if (current_revision)
455
bits['query_string'] = 'r=' + revision;
457
return build_url(bits);
363
460
/** Given a mime type, returns the path to the icon.
364
461
* \param type String, Mime type.
365
462
* \param sizelarge Boolean, optional.
471
/* Available if exactly one file is selected,
594
/* Available if zero or one files are selected,
472
595
* and only if this is a file, not a directory */
473
596
var serve = document.getElementById("act_serve");
474
if (numsel == 1 && !file.isdir)
597
if (numsel <= 1 && !file.isdir && current_file.svnstatus != 'revision')
476
599
serve.setAttribute("class", "choice");
477
serve.setAttribute("href",
478
app_path(serve_app, current_path, filename));
600
serve.setAttribute("onclick",
601
"return maybe_save('The last saved version will be served.')");
603
serve.setAttribute("href",
604
app_path(serve_app, current_path));
606
serve.setAttribute("href",
607
app_path(serve_app, current_path, filename));
482
611
serve.setAttribute("class", "disabled");
483
612
serve.removeAttribute("href");
613
serve.removeAttribute("onclick");
487
617
/* Available if exactly one file is selected,
488
618
* and it is a Python file.
620
var run = document.getElementById("act_run");
622
if (!file.isdir && file.type == "text/x-python" && numsel <= 1
623
&& current_file.svnstatus != 'revision')
627
// In the edit window
628
var localpath = path_join('/home', current_path);
632
// In the browser window
633
var localpath = path_join('/home', current_path, filename);
635
run.setAttribute("class", "choice");
636
run.setAttribute("onclick", "runfile('" + localpath + "')");
640
run.setAttribute("class", "disabled");
641
run.removeAttribute("onclick");
645
/* Always available for current files.
494
646
* If 0 files selected, download the current file or directory as a ZIP.
495
647
* If 1 directory selected, download it as a ZIP.
496
648
* If 1 non-directory selected, download it.
497
649
* If >1 files selected, download them all as a ZIP.
499
651
var download = document.getElementById("act_download");
652
if (current_file.svnstatus == 'revision')
654
download.setAttribute("class", "disabled");
655
download.removeAttribute("onclick");
657
else if (numsel <= 1)
659
download.setAttribute("class", "choice")
504
662
download.setAttribute("href",
542
701
var publish = document.getElementById("act_publish");
543
702
var submit = document.getElementById("act_submit");
544
if (numsel <= 1 && file.isdir)
703
var pubcond = numsel <= 1 && file.isdir;
546
706
/* 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");
707
/* If this dir is already published, call it "Unpublish" */
710
publish.setAttribute("value", "unpublish");
711
publish.setAttribute("title" ,"Make it so this directory "
712
+ "can not be seen by anyone on the web");
713
publish.textContent = "Unpublish";
715
publish.setAttribute("value", "publish");
716
publish.setAttribute("title","Make it so this directory "
717
+ "can be seen by anyone on the web");
718
publish.textContent = "Publish";
721
set_action_state(["publish", "submit"], pubcond);
562
/* If exactly 1 non-directory file is selected/opened, and its parent
724
/* If exactly 1 non-directory file is selected, and its parent
563
725
* directory is 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");
727
set_action_state("share", numsel == 1 && !file.isdir &&
728
current_file.published);
579
731
/* If exactly 1 file is selected */
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");
732
set_action_state("rename", numsel == 1);
592
734
/* Delete, cut, copy */
593
735
/* If >= 1 file is selected */
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");
736
set_action_state(["delete", "cut", "copy"], numsel >= 1);
616
738
/* Paste, new file, new directory, upload */
617
/* Always enabled (assuming this is a directory) */
739
/* Disable if the current file is not a directory */
740
set_action_state(["paste", "newfile", "mkdir", "upload"], current_file.isdir);
619
742
/* Subversion actions */
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");
633
var svncheckout = document.getElementById("act_svncheckout");
634
/* current_path == username: We are at the top level */
635
if (current_path == username)
637
svncheckout.setAttribute("class", "choice");
638
svncheckout.removeAttribute("disabled");
743
/* These are only useful if we are in a versioned directory and have some
745
set_action_state(["svnadd", "svnremove", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
747
/* Diff, log and update only support one path at the moment, so we must
748
* have 0 or 1 versioned files selected. If 0, the directory must be
750
single_versioned_path = (
752
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
753
(numsel == 0 && (svnst = current_file.svnstatus))
754
) && svnst != "unversioned");
755
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
757
/* We can resolve if we have a file selected and it is conflicted. */
758
set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
760
/* Log should be available for revisions as well. */
761
set_action_state("svnlog", single_versioned_path, true);
763
/* There is currently nothing on the More Actions menu of use
764
* when the current file is not a directory. Hence, just remove
766
* (This makes some of the above decisions somewhat redundant).
767
* We also take this opportunity to show the appropriate actions2
768
* bar for this path. It should either be a save or upload widget.
770
if (current_file.isdir)
772
var actions2_directory = document.getElementById("actions2_directory");
773
actions2_directory.setAttribute("style", "display: inline;");
774
var moreactions = document.getElementById("moreactions_area");
775
moreactions.setAttribute("style", "display: inline;");
642
svncheckout.setAttribute("class", "disabled");
643
svncheckout.setAttribute("disabled", "disabled");
779
var actions2_file = document.getElementById("actions2_file");
780
actions2_file.setAttribute("style", "display: inline;");