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.")
245
handle_error("The server returned an invalid directory listing");
297
248
/* Get "." out, it's special */
298
249
current_file = file_listing["."]; /* Global */
299
250
delete file_listing["."];
301
if ('revision' in listing)
303
current_revision = listing.revision;
306
252
/* Check if this is a directory listing or file contents */
307
253
var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
311
home_listing(listing, subjects, path);
256
handle_dir_listing(path, listing);
421
329
/*** 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
428
332
function handle_error(message)
430
334
var files = document.getElementById("filesbody");
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);
335
var txt_elem = dom_make_text_elem("div", "Error: "
336
+ message.toString() + ".")
443
337
txt_elem.setAttribute("class", "padding error");
444
338
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);
460
341
/** Given a mime type, returns the path to the icon.
461
342
* \param type String, Mime type.
462
343
* \param sizelarge Boolean, optional.
608
/* Available if zero or one files are selected,
449
/* Available if exactly one file is selected,
609
450
* and only if this is a file, not a directory */
610
451
var serve = document.getElementById("act_serve");
611
if (numsel <= 1 && !file.isdir && current_file.svnstatus != 'revision')
452
if (numsel == 1 && !file.isdir)
613
454
serve.setAttribute("class", "choice");
614
serve.setAttribute("onclick",
615
"return maybe_save('The last saved version will be served.')");
617
serve.setAttribute("href",
618
app_path(serve_app, current_path));
620
serve.setAttribute("href",
621
app_path(serve_app, current_path, filename));
455
serve.setAttribute("href",
456
app_path(serve_app, current_path, filename));
625
460
serve.setAttribute("class", "disabled");
626
461
serve.removeAttribute("href");
627
serve.removeAttribute("onclick");
631
465
/* Available if exactly one file is selected,
632
466
* and it is a Python file.
634
var run = document.getElementById("act_run");
636
if (numsel <= 1 && !file.isdir && file.type == "text/x-python"
637
&& current_file.svnstatus != 'revision')
641
// In the edit window
642
var localpath = path_join('/home', current_path);
646
// In the browser window
647
var localpath = path_join('/home', current_path, filename);
649
run.setAttribute("class", "choice");
650
run.setAttribute("onclick", "runfile('" + localpath + "')");
654
run.setAttribute("class", "disabled");
655
run.removeAttribute("onclick");
659
/* Always available for current files.
660
472
* If 0 files selected, download the current file or directory as a ZIP.
661
473
* If 1 directory selected, download it as a ZIP.
662
474
* If 1 non-directory selected, download it.
663
475
* If >1 files selected, download them all as a ZIP.
665
477
var download = document.getElementById("act_download");
666
if (current_file.svnstatus == 'revision')
668
download.setAttribute("class", "disabled");
669
download.removeAttribute("onclick");
671
else if (numsel <= 1)
673
download.setAttribute("class", "choice")
676
482
download.setAttribute("href",
715
520
var publish = document.getElementById("act_publish");
716
521
var submit = document.getElementById("act_submit");
717
var pubcond = numsel <= 1 && file.isdir;
720
/* If this dir is already published, call it "Unpublish" */
723
publish.setAttribute("value", "unpublish");
724
publish.setAttribute("title" ,"Make it so this directory "
725
+ "can not be seen by anyone on the web");
726
publish.textContent = "Unpublish";
728
publish.setAttribute("value", "publish");
729
publish.setAttribute("title","Make it so this directory "
730
+ "can be seen by anyone on the web");
731
publish.textContent = "Publish";
734
set_action_state(["publish", "submit"], pubcond);
522
if (numsel <= 1 && file.isdir)
524
/* TODO: Work out of file is svn'd */
525
/* TODO: If this dir is already published, call it "Unpublish" */
526
publish.setAttribute("class", "choice");
527
publish.removeAttribute("disabled");
528
submit.setAttribute("class", "choice");
529
submit.removeAttribute("disabled");
533
publish.setAttribute("class", "disabled");
534
publish.setAttribute("disabled", "disabled");
535
submit.setAttribute("class", "disabled");
536
submit.setAttribute("disabled", "disabled");
737
/* If exactly 1 non-directory file is selected, and its parent
540
/* If exactly 1 non-directory file is selected/opened, and its parent
738
541
* directory is published.
740
set_action_state("share", numsel == 1 && !file.isdir &&
741
current_file.published);
543
var share = document.getElementById("act_share");
544
if (numsel <= 1 && !file.isdir)
546
/* TODO: Work out if parent dir is published */
547
share.setAttribute("class", "choice");
548
share.removeAttribute("disabled");
552
share.setAttribute("class", "disabled");
553
share.setAttribute("disabled", "disabled");
744
557
/* If exactly 1 file is selected */
745
set_action_state("rename", numsel == 1);
558
var rename = document.getElementById("act_rename");
561
rename.setAttribute("class", "choice");
562
rename.removeAttribute("disabled");
566
rename.setAttribute("class", "disabled");
567
rename.setAttribute("disabled", "disabled");
747
570
/* Delete, cut, copy */
748
571
/* If >= 1 file is selected */
749
set_action_state(["delete", "cut", "copy"], numsel >= 1);
572
var act_delete = document.getElementById("act_delete");
573
var cut = document.getElementById("act_cut");
574
var copy = document.getElementById("act_copy");
577
act_delete.setAttribute("class", "choice");
578
act_delete.removeAttribute("disabled");
579
cut.setAttribute("class", "choice");
580
cut.removeAttribute("disabled");
581
copy.setAttribute("class", "choice");
582
copy.removeAttribute("disabled");
586
act_delete.setAttribute("class", "disabled");
587
act_delete.setAttribute("disabled", "disabled");
588
cut.setAttribute("class", "disabled");
589
cut.setAttribute("disabled", "disabled");
590
copy.setAttribute("class", "disabled");
591
copy.setAttribute("disabled", "disabled");
751
594
/* Paste, new file, new directory, upload */
752
/* Disable if the current file is not a directory */
753
set_action_state(["paste", "newfile", "mkdir", "upload"], current_file.isdir);
595
/* Always enabled (assuming this is a directory) */
755
597
/* Subversion actions */
756
/* These are only useful if we are in a versioned directory and have some
758
set_action_state(["svnadd",], numsel >= 1 && current_file.svnstatus);
759
/* And these are only usefull is ALL the selected files are versioned */
760
set_action_state(["svnremove", "svnrevert", "svncommit", "svncopy",
761
"svncut"], numsel >= 1 && current_file.svnstatus && svn_selection);
763
/* Diff, log and update only support one path at the moment, so we must
764
* have 0 or 1 versioned files selected. If 0, the directory must be
766
single_versioned_path = (
768
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
769
(numsel == 0 && (svnst = current_file.svnstatus))
770
) && svnst != "unversioned");
771
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
773
/* We can resolve if we have a file selected and it is conflicted. */
774
set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
776
/* Log should be available for revisions as well. */
777
set_action_state("svnlog", single_versioned_path, true);
779
/* There is currently nothing on the More Actions menu of use
780
* when the current file is not a directory. Hence, just remove
782
* (This makes some of the above decisions somewhat redundant).
783
* We also take this opportunity to show the appropriate actions2
784
* bar for this path. It should either be a save or upload widget.
786
if (current_file.isdir)
788
var actions2_directory = document.getElementById("actions2_directory");
789
actions2_directory.setAttribute("style", "display: inline;");
790
var moreactions = document.getElementById("moreactions_area");
791
moreactions.setAttribute("style", "display: inline;");
795
var actions2_file = document.getElementById("actions2_file");
796
actions2_file.setAttribute("style", "display: inline;");
598
/* TODO: Work out when these are appropriate */
599
var svnadd = document.getElementById("act_svnadd");
600
var svnrevert = document.getElementById("act_svnrevert");
601
var svncommit = document.getElementById("act_svncommit");
604
svnadd.setAttribute("class", "choice");
605
svnadd.removeAttribute("disabled");
606
svnrevert.setAttribute("class", "choice");
607
svnrevert.removeAttribute("disabled");
608
svncommit.setAttribute("class", "choice");
609
svncommit.removeAttribute("disabled");
865
678
action_add(selected_files);
868
action_remove(selected_files);
870
680
case "svnrevert":
871
681
action_revert(selected_files);
874
window.location = path_join(app_path('diff'), current_path, selected_files[0] || '');
877
action_update(selected_files);
880
action_resolved(selected_files);
882
683
case "svncommit":
883
684
action_commit(selected_files);
886
window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
889
action_svncopy(selected_files);
892
action_svncut(selected_files);
897
/** User clicks "Run" button.
898
* Do an Ajax call and print the test output.
900
function runfile(localpath)
902
if (!maybe_save('The last saved version will be run.')) return false;
904
/* Dump the entire file to the console */
905
var callback = function()
907
console_enter_line("execfile('" + localpath + "')", "block");
909
start_server(callback)
913
689
/** Called when the page loads initially.
915
function browser_init()
691
window.onload = function()
917
693
/* Navigate (internally) to the path in the URL bar.
918
694
* This causes the page to be populated with whatever is at that address,