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
"conflicted": "conflicted.png",
72
69
"revision": "revision.png"
75
72
/* Mapping SVN status to "nice" strings */
77
74
"unversioned": "Temporary file",
78
"ignored": "Temporary file (ignored)",
79
75
"normal": "Permanent file",
80
76
"added": "Temporary file (scheduled to be added)",
81
77
"missing": "Permanent file (missing)",
90
86
default_svn_icon = null;
91
87
default_svn_nice = "Unknown status";
93
svn_icons_path = "+media/ivle.webapp.core/images/svn";
89
svn_icons_path = "media/images/svn";
95
published_icon = "+media/ivle.webapp.core/images/interface/published.png";
91
published_icon = "media/images/interface/published.png";
97
93
/* List of MIME types considered "executable" by the system.
98
94
* Executable files offer a "run" link, implying that the "serve"
137
133
* May be "application/x-www-form-urlencoded" or "multipart/form-data".
138
134
* Defaults to "application/x-www-form-urlencoded".
139
135
* "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)
137
function do_action(action, path, args, content_type, ignore_response)
145
139
args.action = action;
146
140
/* Callback action, when the server returns */
147
var callback_inner = function(response)
141
var callback = function(response)
149
143
/* Check for action errors reported by the server, and report them
151
145
var error = response.getResponseHeader("X-IVLE-Action-Error");
152
if (error != null && error != "")
153
147
/* Note: This header (in particular) comes URI-encoded, to
154
148
* allow multi-line error messages. Decode */
155
149
alert("Error: " + decodeURIComponent(error.toString()) + ".");
156
150
/* Now read the response and set up the page accordingly */
157
if (callback != null)
158
callback(path, response);
151
if (ignore_response != true)
152
handle_response(path, response, true);
160
154
/* Call the server and perform the action. This mutates the server. */
161
ajax_call(callback_inner, service_app, path, args, "POST", content_type);
155
ajax_call(callback, service_app, path, args, "POST", content_type);
164
158
/** Calls the server using Ajax, requesting a directory listing. This should
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
var top_level_dir = path==username;
256
var req = ajax_call(null, "userservice", "get_enrolments", null, "GET")
257
subjects = decode_response(req);
261
243
/* This will always return a listing, whether it is a dir or a file.
263
245
var listing = response.responseText;
315
297
var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
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);
300
handle_dir_listing(path, listing);
394
366
upload_callback_count++;
395
367
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
data = myFrame.firstChild.getElementsByTagName(
402
'body')[0].firstChild.firstChild.nodeValue;
403
data = JSON.parse(data);
405
alert("Error: " + decodeURIComponent(data['Error']));
406
369
document.getElementsByName('data')[0].value = '';
425
388
function maybe_save(warning)
427
390
if (warning == null) warning = '';
428
if (current_file == null || current_file.isdir) return true;
391
if (current_file.isdir) return true;
429
392
if (document.getElementById("save_button").disabled) return true;
430
393
return confirm("This file has unsaved changes. " + warning +
431
394
"\nAre you sure you wish to continue?");
543
499
var div = document.createElement("div");
544
500
files.appendChild(div);
545
501
div.setAttribute("class", "padding");
546
var download_link = app_url(download_app, path);
502
var download_link = app_path(download_app, path);
547
503
var par1 = dom_make_text_elem("p",
548
504
"The file " + path + " is a binary file. To download this file, " +
549
505
"click the following link:");
648
590
"return maybe_save('The last saved version will be served.')");
650
592
serve.setAttribute("href",
651
app_url(serve_app, current_path));
593
app_path(serve_app, current_path));
653
595
serve.setAttribute("href",
654
app_url(serve_app, current_path, filename));
596
app_path(serve_app, current_path, filename));
720
662
download.setAttribute("href",
721
app_url(download_app, current_path, filename));
663
app_path(download_app, current_path, filename));
723
665
download.setAttribute("title",
724
666
"Download the selected directory as a ZIP file");
732
674
/* Make a query string with all the files to download */
733
var dlpath = app_url(download_app, current_path) + "?";
675
var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
734
676
for (var i=0; i<numsel; i++)
735
677
dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
736
678
dlpath = dlpath.substr(0, dlpath.length-1);
750
692
var pubcond = numsel <= 1 && file.isdir;
695
/* TODO: Work out of file is svn'd */
753
696
/* If this dir is already published, call it "Unpublish" */
754
697
if (file.published)
756
699
publish.setAttribute("value", "unpublish");
757
700
publish.setAttribute("title" ,"Make it so this directory "
758
701
+ "can not be seen by anyone on the web");
759
publish.firstChild.nodeValue = "Unpublish";
702
publish.textContent = "Unpublish";
761
704
publish.setAttribute("value", "publish");
762
705
publish.setAttribute("title","Make it so this directory "
763
706
+ "can be seen by anyone on the web");
764
publish.firstChild.nodeValue = "Publish";
707
publish.textContent = "Publish";
767
710
set_action_state(["publish", "submit"], pubcond);
788
731
/* Subversion actions */
789
732
/* These are only useful if we are in a versioned directory and have some
790
733
* files selected. */
791
set_action_state(["svnadd"], numsel >= 1 && current_file.svnstatus);
792
/* And these are only useful is ALL the selected files are versioned */
793
set_action_state(["svnremove", "svnrevert", "svncopy", "svncut"],
794
numsel >= 1 && current_file.svnstatus && svn_selection);
795
/* Commit is useful if ALL selected files are versioned, or the current
796
* directory is versioned */
797
set_action_state(["svncommit"], current_file.svnstatus &&
798
(numsel >= 1 && svn_selection || numsel == 0));
734
set_action_state(["svnadd", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
800
/* Diff, log and update only support one path at the moment, so we must
801
* have 0 or 1 versioned files selected. If 0, the directory must be
736
/* Diff and log only support one path at the moment, so we must have 0 or 1
737
* versioned files selected. If 0, the directory must be versioned. */
803
738
single_versioned_path = (
805
740
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
806
741
(numsel == 0 && (svnst = current_file.svnstatus))
807
) && svnstatus_versioned(svnst));
808
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
810
/* We can resolve if we have a file selected and it is conflicted. */
811
set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
742
) && svnst != "unversioned");
743
set_action_state("svndiff", single_versioned_path);
813
745
/* Log should be available for revisions as well. */
814
746
set_action_state("svnlog", single_versioned_path, true);
816
/* Cleanup should be available for revisions as well. */
817
set_action_state("svncleanup", single_versioned_path, true);
819
single_ivle_versioned_path = (
821
(numsel == 1 && (stat = file_listing[selected_files[0]])) ||
822
(numsel == 0 && (stat = current_file))
823
) && svnstatus_versioned(stat.svnstatus)
825
&& stat.svnurl.substr(0, svn_base.length) == svn_base);
826
set_action_state(["submit"], single_ivle_versioned_path);
748
/* current_path == username: We are at the top level */
749
set_action_state("svncheckout", current_path == username);
828
751
/* There is currently nothing on the More Actions menu of use
829
752
* when the current file is not a directory. Hence, just remove
879
802
action_unpublish(selected_files);
882
window.open(public_app_url("~" + current_path, filename), 'share')
805
//alert("Not yet implemented: Sharing files");
806
window.open(public_app_path(serve_app, current_path, filename), 'share')
885
if (selected_files.length == 1)
886
stat = file_listing[selected_files[0]];
889
url = stat.svnurl.substr(svn_base.length); // URL-encoded
890
path = decodeURIComponent(url);
892
/* The working copy might not have an up-to-date version of the
893
* directory. While submitting like this could yield unexpected
894
* results, we should really submit the latest revision to minimise
895
* terrible mistakes - so we run off and ask fileservice for the
897
$.post(app_path(service_app, current_path),
898
{"action": "svnrepostat", "path": path},
901
window.location = path_join(app_path('+submit'), url) + '?revision=' + result.svnrevision;
810
alert("Not yet implemented: Submit");
907
813
action_rename(filename);
910
action_delete(selected_files);
816
action_remove(selected_files);
913
819
action_copy(selected_files);
931
837
action_add(selected_files);
934
action_remove(selected_files);
936
839
case "svnrevert":
937
840
action_revert(selected_files);
940
window.location = path_join(app_url('diff'), current_path, selected_files[0] || '');
943
action_update(selected_files);
946
action_resolved(selected_files);
843
window.location = path_join(app_path('diff'), current_path, selected_files[0] || '');
948
845
case "svncommit":
949
846
action_commit(selected_files);
952
window.location = path_join(app_url('svnlog'), current_path, selected_files[0] || '');
955
action_svncopy(selected_files);
958
action_svncut(selected_files);
961
action_svncleanup(".");
849
window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');