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);
395
378
if (upload_callback_count >= 2)
397
380
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;
381
data = myFrame.firstChild.childNodes[1].firstChild.firstChild.nodeValue;
404
382
data = JSON.parse(data);
405
383
if ('Error' in data)
406
384
alert("Error: " + decodeURIComponent(data['Error']));
426
404
function maybe_save(warning)
428
406
if (warning == null) warning = '';
429
if (current_file == null || current_file.isdir) return true;
407
if (current_file.isdir) return true;
430
408
if (document.getElementById("save_button").disabled) return true;
431
409
return confirm("This file has unsaved changes. " + warning +
432
410
"\nAre you sure you wish to continue?");
529
507
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
510
/** Displays a download link to the binary file.
541
512
function handle_binary(path)
544
515
var div = document.createElement("div");
545
516
files.appendChild(div);
546
517
div.setAttribute("class", "padding");
547
var download_link = app_url(download_app, path);
518
var download_link = app_path(download_app, path);
548
519
var par1 = dom_make_text_elem("p",
549
520
"The file " + path + " is a binary file. To download this file, " +
550
521
"click the following link:");
649
620
"return maybe_save('The last saved version will be served.')");
651
622
serve.setAttribute("href",
652
app_url(serve_app, current_path));
623
app_path(serve_app, current_path));
654
625
serve.setAttribute("href",
655
app_url(serve_app, current_path, filename));
626
app_path(serve_app, current_path, filename));
710
681
download.setAttribute("href",
711
app_url(download_app, current_path));
682
app_path(download_app, current_path));
713
684
download.setAttribute("title",
714
685
"Download the current directory as a ZIP file");
721
692
download.setAttribute("href",
722
app_url(download_app, current_path, filename));
693
app_path(download_app, current_path, filename));
724
695
download.setAttribute("title",
725
696
"Download the selected directory as a ZIP file");
733
704
/* Make a query string with all the files to download */
734
var dlpath = app_url(download_app, current_path) + "?";
705
var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
735
706
for (var i=0; i<numsel; i++)
736
707
dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
737
708
dlpath = dlpath.substr(0, dlpath.length-1);
757
728
publish.setAttribute("value", "unpublish");
758
729
publish.setAttribute("title" ,"Make it so this directory "
759
730
+ "can not be seen by anyone on the web");
760
publish.firstChild.nodeValue = "Unpublish";
731
publish.textContent = "Unpublish";
762
733
publish.setAttribute("value", "publish");
763
734
publish.setAttribute("title","Make it so this directory "
764
735
+ "can be seen by anyone on the web");
765
publish.firstChild.nodeValue = "Publish";
736
publish.textContent = "Publish";
768
739
set_action_state(["publish", "submit"], pubcond);
789
760
/* Subversion actions */
790
761
/* These are only useful if we are in a versioned directory and have some
791
762
* 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));
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);
802
768
/* Diff, log and update only support one path at the moment, so we must
803
769
* have 0 or 1 versioned files selected. If 0, the directory must be
807
773
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
808
774
(numsel == 0 && (svnst = current_file.svnstatus))
809
) && svnstatus_versioned(svnst));
775
) && svnst != "unversioned");
810
776
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
812
778
/* We can resolve if we have a file selected and it is conflicted. */
815
781
/* Log should be available for revisions as well. */
816
782
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
784
/* There is currently nothing on the More Actions menu of use
831
785
* when the current file is not a directory. Hence, just remove
881
835
action_unpublish(selected_files);
884
window.open(public_app_url("~" + current_path, filename), 'share')
838
//alert("Not yet implemented: Sharing files");
839
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;
843
alert("Not yet implemented: Submit");
909
846
action_rename(filename);
933
870
action_add(selected_files);
935
872
case "svnremove":
936
action_svnremove(selected_files);
939
action_svnrename(selected_files);
873
action_remove(selected_files);
941
875
case "svnrevert":
942
876
action_revert(selected_files);
945
window.location = path_join(app_url('diff'), current_path, selected_files[0] || '');
879
window.location = path_join(app_path('diff'), current_path, selected_files[0] || '');
947
881
case "svnupdate":
948
882
action_update(selected_files);
954
888
action_commit(selected_files);
957
window.location = path_join(app_url('svnlog'), current_path, selected_files[0] || '');
891
window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
960
894
action_svncopy(selected_files);
992
923
* This causes the page to be populated with whatever is at that address,
993
924
* 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
926
var path = parse_url(window.location.href).path;
1002
927
/* Strip out root_dir + "/files" from the front of the path */
1003
928
var strip = make_path(this_app);