55
55
default_type_icon = "txt.png";
57
57
/* Relative to IVLE root */
58
type_icons_path = "+media/ivle.webapp.core/images/mime";
59
type_icons_path_large = "+media/ivle.webapp.core/images/mime/large";
58
type_icons_path = "media/images/mime";
59
type_icons_path_large = "media/images/mime/large";
61
61
/* Mapping SVN status to icons, just the file's basename */
63
"unversioned": "unversioned.png",
64
"ignored": null, /* Supposed to be innocuous */
65
64
"normal": "normal.png",
66
65
"added": "added.png",
67
66
"missing": "missing.png",
68
67
"deleted": "deleted.png",
69
"replaced": "replaced.png",
70
68
"modified": "modified.png",
71
69
"conflicted": "conflicted.png",
72
70
"revision": "revision.png"
75
73
/* Mapping SVN status to "nice" strings */
77
75
"unversioned": "Temporary file",
78
"ignored": "Temporary file (ignored)",
79
76
"normal": "Permanent file",
80
77
"added": "Temporary file (scheduled to be added)",
81
78
"missing": "Permanent file (missing)",
90
87
default_svn_icon = null;
91
88
default_svn_nice = "Unknown status";
93
svn_icons_path = "+media/ivle.webapp.core/images/svn";
90
svn_icons_path = "media/images/svn";
95
published_icon = "+media/ivle.webapp.core/images/interface/published.png";
92
published_icon = "media/images/interface/published.png";
97
94
/* List of MIME types considered "executable" by the system.
98
95
* Executable files offer a "run" link, implying that the "serve"
137
134
* May be "application/x-www-form-urlencoded" or "multipart/form-data".
138
135
* Defaults to "application/x-www-form-urlencoded".
139
136
* "multipart/form-data" is recommended for large uploads.
140
* \param callback, optional.
141
* A callback function for after the action has been handled.
143
function do_action(action, path, args, content_type, callback)
138
function do_action(action, path, args, content_type, ignore_response)
145
140
args.action = action;
146
141
/* Callback action, when the server returns */
147
var callback_inner = function(response)
142
var callback = function(response)
149
144
/* Check for action errors reported by the server, and report them
151
146
var error = response.getResponseHeader("X-IVLE-Action-Error");
152
if (error != null && error != "")
153
148
/* Note: This header (in particular) comes URI-encoded, to
154
149
* allow multi-line error messages. Decode */
155
150
alert("Error: " + decodeURIComponent(error.toString()) + ".");
156
151
/* Now read the response and set up the page accordingly */
157
if (callback != null)
158
callback(path, response);
152
if (ignore_response != true)
153
handle_response(path, response, true);
160
155
/* Call the server and perform the action. This mutates the server. */
161
ajax_call(callback_inner, service_app, path, args, "POST", content_type);
156
ajax_call(callback, service_app, path, args, "POST", content_type);
164
159
/** Calls the server using Ajax, requesting a directory listing. This should
249
244
var subjects = null;
250
/* Remove trailing slash (or path==username won't compare properly) */
251
if (path[path.length-1] == "/")
252
path = path.substr(0, path.length-1);
253
245
var top_level_dir = path==username;
254
246
if (top_level_dir)
318
310
setup_for_listing();
321
/* Top-level dir, with subjects */
322
special_home_listing(listing, subjects, path);
326
/* Not the top-level dir. Do a normal dir listing. */
327
handle_dir_listing(path, listing.listing);
311
home_listing(listing, subjects, path);
394
377
upload_callback_count++;
395
378
if (upload_callback_count >= 2)
397
myFrame = frames['upload_iframe'].document;
398
/* Browsers will turn the raw returned JSON into an HTML document. We
399
* need to get the <pre> from inside the <body>, and look at its text.
401
var pre = myFrame.firstChild.getElementsByTagName(
402
'body')[0].firstChild;
403
var data = pre.innerText || pre.textContent;
404
data = JSON.parse(data);
406
alert("Error: " + decodeURIComponent(data['Error']));
407
380
document.getElementsByName('data')[0].value = '';
426
399
function maybe_save(warning)
428
401
if (warning == null) warning = '';
429
if (current_file == null || current_file.isdir) return true;
402
if (current_file.isdir) return true;
430
403
if (document.getElementById("save_button").disabled) return true;
431
404
return confirm("This file has unsaved changes. " + warning +
432
405
"\nAre you sure you wish to continue?");
529
502
return default_svn_nice;
532
/** Returns true if a file is versioned (not unversioned or ignored).
534
function svnstatus_versioned(svnstatus)
536
return svnstatus != "unversioned" && svnstatus != "ignored";
539
505
/** Displays a download link to the binary file.
541
507
function handle_binary(path)
544
510
var div = document.createElement("div");
545
511
files.appendChild(div);
546
512
div.setAttribute("class", "padding");
547
var download_link = app_url(download_app, path);
513
var download_link = app_path(download_app, path);
548
514
var par1 = dom_make_text_elem("p",
549
515
"The file " + path + " is a binary file. To download this file, " +
550
516
"click the following link:");
582
/* Updates the list of available actions based on files selected */
583
548
function update_actions()
586
551
var numsel = selected_files.length;
587
var svn_selection = false;
591
svn_selection = true;
592
for (var i = 0; i < selected_files.length; i++){
593
if (!svnstatus_versioned(file_listing[selected_files[i]].svnstatus))
595
svn_selection = false;
649
601
"return maybe_save('The last saved version will be served.')");
651
603
serve.setAttribute("href",
652
app_url(serve_app, current_path));
604
app_path(serve_app, current_path));
654
606
serve.setAttribute("href",
655
app_url(serve_app, current_path, filename));
607
app_path(serve_app, current_path, filename));
668
620
var run = document.getElementById("act_run");
670
if (numsel <= 1 && !file.isdir && file.type == "text/x-python"
671
&& current_file.svnstatus != 'revision')
622
if (!file.isdir && file.type == "text/x-python" && numsel <= 1
623
&& current_file.svnstatus != 'revision')
710
662
download.setAttribute("href",
711
app_url(download_app, current_path));
663
app_path(download_app, current_path));
713
665
download.setAttribute("title",
714
666
"Download the current directory as a ZIP file");
721
673
download.setAttribute("href",
722
app_url(download_app, current_path, filename));
674
app_path(download_app, current_path, filename));
724
676
download.setAttribute("title",
725
677
"Download the selected directory as a ZIP file");
733
685
/* Make a query string with all the files to download */
734
var dlpath = app_url(download_app, current_path) + "?";
686
var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
735
687
for (var i=0; i<numsel; i++)
736
688
dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
737
689
dlpath = dlpath.substr(0, dlpath.length-1);
751
703
var pubcond = numsel <= 1 && file.isdir;
706
/* TODO: Work out of file is svn'd */
754
707
/* If this dir is already published, call it "Unpublish" */
755
708
if (file.published)
757
710
publish.setAttribute("value", "unpublish");
758
711
publish.setAttribute("title" ,"Make it so this directory "
759
712
+ "can not be seen by anyone on the web");
760
publish.firstChild.nodeValue = "Unpublish";
713
publish.textContent = "Unpublish";
762
715
publish.setAttribute("value", "publish");
763
716
publish.setAttribute("title","Make it so this directory "
764
717
+ "can be seen by anyone on the web");
765
publish.firstChild.nodeValue = "Publish";
718
publish.textContent = "Publish";
768
721
set_action_state(["publish", "submit"], pubcond);
789
742
/* Subversion actions */
790
743
/* These are only useful if we are in a versioned directory and have some
791
744
* files selected. */
792
set_action_state(["svnrename"], numsel == 1 && current_file.svnstatus);
793
set_action_state(["svnadd"], numsel >= 1 && current_file.svnstatus);
794
/* And these are only useful is ALL the selected files are versioned */
795
set_action_state(["svnremove", "svnrevert", "svncopy", "svncut"],
796
numsel >= 1 && current_file.svnstatus && svn_selection);
797
/* Commit is useful if ALL selected files are versioned, or the current
798
* directory is versioned */
799
set_action_state(["svncommit"], current_file.svnstatus &&
800
(numsel >= 1 && svn_selection || numsel == 0));
745
set_action_state(["svnadd", "svnremove", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
802
747
/* Diff, log and update only support one path at the moment, so we must
803
748
* have 0 or 1 versioned files selected. If 0, the directory must be
807
752
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
808
753
(numsel == 0 && (svnst = current_file.svnstatus))
809
) && svnstatus_versioned(svnst));
754
) && svnst != "unversioned");
810
755
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
812
757
/* We can resolve if we have a file selected and it is conflicted. */
815
760
/* Log should be available for revisions as well. */
816
761
set_action_state("svnlog", single_versioned_path, true);
818
/* Cleanup should be available for revisions as well. */
819
set_action_state("svncleanup", single_versioned_path, true);
821
single_ivle_versioned_path = (
823
(numsel == 1 && (stat = file_listing[selected_files[0]])) ||
824
(numsel == 0 && (stat = current_file))
825
) && svnstatus_versioned(stat.svnstatus)
827
&& stat.svnurl.substr(0, svn_base.length) == svn_base);
828
set_action_state(["submit"], single_ivle_versioned_path);
830
763
/* There is currently nothing on the More Actions menu of use
831
764
* when the current file is not a directory. Hence, just remove
881
814
action_unpublish(selected_files);
884
window.open(public_app_url("~" + current_path, filename), 'share')
817
//alert("Not yet implemented: Sharing files");
818
window.open(public_app_path(serve_app, current_path, filename), 'share')
887
if (selected_files.length == 1)
888
stat = file_listing[selected_files[0]];
891
url = stat.svnurl.substr(svn_base.length); // URL-encoded
892
path = decodeURIComponent(url);
894
/* The working copy might not have an up-to-date version of the
895
* directory. While submitting like this could yield unexpected
896
* results, we should really submit the latest revision to minimise
897
* terrible mistakes - so we run off and ask fileservice for the
899
$.post(app_path(service_app, current_path),
900
{"action": "svnrepostat", "path": path},
903
window.location = path_join(app_path('+submit'), url) + '?revision=' + result.svnrevision;
822
alert("Not yet implemented: Submit");
909
825
action_rename(filename);
933
849
action_add(selected_files);
935
851
case "svnremove":
936
action_svnremove(selected_files);
939
action_svnrename(selected_files);
852
action_remove(selected_files);
941
854
case "svnrevert":
942
855
action_revert(selected_files);
945
window.location = path_join(app_url('diff'), current_path, selected_files[0] || '');
858
window.location = path_join(app_path('diff'), current_path, selected_files[0] || '');
947
860
case "svnupdate":
948
861
action_update(selected_files);
954
867
action_commit(selected_files);
957
window.location = path_join(app_url('svnlog'), current_path, selected_files[0] || '');
960
action_svncopy(selected_files);
963
action_svncut(selected_files);
966
action_svncleanup(".");
870
window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
992
896
* This causes the page to be populated with whatever is at that address,
993
897
* whether it be a directory or a file.
995
var path = get_path();
999
/** Gets the current path of the window */
1000
function get_path() {
1001
899
var path = parse_url(window.location.href).path;
1002
900
/* Strip out root_dir + "/files" from the front of the path */
1003
901
var strip = make_path(this_app);