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
64
"normal": "normal.png",
65
65
"added": "added.png",
66
66
"missing": "missing.png",
67
67
"deleted": "deleted.png",
68
68
"modified": "modified.png",
69
"conflicted": "conflicted.png",
70
69
"revision": "revision.png"
87
86
default_svn_icon = null;
88
87
default_svn_nice = "Unknown status";
90
svn_icons_path = "+media/ivle.webapp.core/images/svn";
89
svn_icons_path = "media/images/svn";
92
published_icon = "+media/ivle.webapp.core/images/interface/published.png";
91
published_icon = "media/images/interface/published.png";
94
93
/* List of MIME types considered "executable" by the system.
95
94
* Executable files offer a "run" link, implying that the "serve"
134
132
* May be "application/x-www-form-urlencoded" or "multipart/form-data".
135
133
* Defaults to "application/x-www-form-urlencoded".
136
134
* "multipart/form-data" is recommended for large uploads.
137
* \param callback, optional.
138
* A callback function for after the action has been handled.
140
function do_action(action, path, args, content_type, callback)
136
function do_action(action, path, args, content_type, ignore_response)
142
138
args.action = action;
143
139
/* Callback action, when the server returns */
144
var callback_inner = function(response)
140
var callback = function(response)
146
142
/* Check for action errors reported by the server, and report them
148
144
var error = response.getResponseHeader("X-IVLE-Action-Error");
149
if (error != null && error != "")
150
146
/* Note: This header (in particular) comes URI-encoded, to
151
147
* allow multi-line error messages. Decode */
152
148
alert("Error: " + decodeURIComponent(error.toString()) + ".");
153
149
/* Now read the response and set up the page accordingly */
154
if (callback != null)
155
callback(path, response);
150
if (ignore_response != true)
151
handle_response(path, response, true);
157
153
/* Call the server and perform the action. This mutates the server. */
158
ajax_call(callback_inner, service_app, path, args, "POST", content_type);
154
ajax_call(callback, service_app, path, args, "POST", content_type);
161
157
/** Calls the server using Ajax, requesting a directory listing. This should
247
var top_level_dir = path==username;
250
var req = ajax_call(null, "userservice", "get_enrolments", null, "GET")
251
subjects = decode_response(req);
255
242
/* This will always return a listing, whether it is a dir or a file.
257
244
var listing = response.responseText;
300
287
current_file = file_listing["."]; /* Global */
301
288
delete file_listing["."];
303
if ('revision' in listing)
305
current_revision = listing.revision;
308
290
/* Check if this is a directory listing or file contents */
309
291
var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
313
home_listing(listing, subjects, path);
294
handle_dir_listing(path, listing);
379
360
upload_callback_count++;
380
361
if (upload_callback_count >= 2)
382
myFrame = frames['upload_iframe'].document;
383
/* Browsers will turn the raw returned JSON into an HTML document. We
384
* need to get the <pre> from inside the <body>, and look at its text.
386
data = myFrame.firstChild.getElementsByTagName(
387
'body')[0].firstChild.firstChild.nodeValue;
388
data = JSON.parse(data);
390
alert("Error: " + decodeURIComponent(data['Error']));
391
363
document.getElementsByName('data')[0].value = '';
455
427
files.appendChild(txt_elem);
458
/** Given a path, filename and optional revision, returns a URL to open that
459
* revision of that file.
461
function build_revision_url(path, filename, revision)
463
bits = {'path': app_path(this_app, path, filename)};
464
if (current_revision)
466
bits['query_string'] = 'r=' + revision;
468
return build_url(bits);
471
430
/** Given a mime type, returns the path to the icon.
472
431
* \param type String, Mime type.
473
432
* \param sizelarge Boolean, optional.
534
493
/* Enable or disable actions1 moreactions actions. Takes either a single
535
494
* name, or an array of them.*/
536
function set_action_state(names, which, allow_on_revision)
495
function set_action_state(names, which)
538
497
if (!(names instanceof Array)) names = Array(names);
540
499
for (var i=0; i < names.length; i++)
542
501
element = document.getElementById('act_' + names[i]);
544
!(current_file.svnstatus == 'revision' && !allow_on_revision))
547
505
element.setAttribute("class", "choice");
559
/* Updates the list of available actions based on files selected */
560
517
function update_actions()
563
520
var numsel = selected_files.length;
564
var svn_selection = false;
568
svn_selection = true;
569
for (var i = 0; i < selected_files.length; i++){
570
if (file_listing[selected_files[i]]["svnstatus"] == "unversioned")
572
svn_selection = false;
606
550
open.setAttribute("title",
607
551
"Edit or view this file");
608
open.setAttribute("href", build_revision_url(current_path, filename,
552
open.setAttribute("href", app_path(this_app, current_path, filename));
619
562
/* Available if zero or one files are selected,
620
563
* and only if this is a file, not a directory */
621
564
var serve = document.getElementById("act_serve");
622
if (numsel <= 1 && !file.isdir && current_file.svnstatus != 'revision')
565
if (numsel <= 1 && !file.isdir)
624
567
serve.setAttribute("class", "choice");
625
568
serve.setAttribute("onclick",
670
/* Always available for current files.
671
613
* If 0 files selected, download the current file or directory as a ZIP.
672
614
* If 1 directory selected, download it as a ZIP.
673
615
* If 1 non-directory selected, download it.
674
616
* If >1 files selected, download them all as a ZIP.
676
618
var download = document.getElementById("act_download");
677
if (current_file.svnstatus == 'revision')
679
download.setAttribute("class", "disabled");
680
download.removeAttribute("onclick");
682
else if (numsel <= 1)
684
download.setAttribute("class", "choice")
687
623
download.setAttribute("href",
712
648
for (var i=0; i<numsel; i++)
713
649
dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
714
650
dlpath = dlpath.substr(0, dlpath.length-1);
715
download.setAttribute("class", "choice")
716
651
download.setAttribute("href", dlpath);
717
652
download.setAttribute("title",
718
653
"Download the selected files as a ZIP file");
728
663
var pubcond = numsel <= 1 && file.isdir;
666
/* TODO: Work out of file is svn'd */
731
667
/* If this dir is already published, call it "Unpublish" */
732
668
if (file.published)
734
670
publish.setAttribute("value", "unpublish");
735
671
publish.setAttribute("title" ,"Make it so this directory "
736
672
+ "can not be seen by anyone on the web");
737
publish.firstChild.nodeValue = "Unpublish";
673
publish.textContent = "Unpublish";
739
675
publish.setAttribute("value", "publish");
740
676
publish.setAttribute("title","Make it so this directory "
741
677
+ "can be seen by anyone on the web");
742
publish.firstChild.nodeValue = "Publish";
678
publish.textContent = "Publish";
745
681
set_action_state(["publish", "submit"], pubcond);
766
702
/* Subversion actions */
767
703
/* These are only useful if we are in a versioned directory and have some
768
704
* files selected. */
769
set_action_state(["svnadd"], numsel >= 1 && current_file.svnstatus);
770
/* And these are only usefull is ALL the selected files are versioned */
771
set_action_state(["svnremove", "svnrevert", "svncommit", "svncopy",
772
"svncut"], numsel >= 1 && current_file.svnstatus && svn_selection);
774
/* Diff, log and update only support one path at the moment, so we must
775
* have 0 or 1 versioned files selected. If 0, the directory must be
777
single_versioned_path = (
779
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
780
(numsel == 0 && (svnst = current_file.svnstatus))
781
) && svnst != "unversioned");
782
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
784
/* We can resolve if we have a file selected and it is conflicted. */
785
set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
787
/* Log should be available for revisions as well. */
788
set_action_state("svnlog", single_versioned_path, true);
790
/* Cleanup should be available for revisions as well. */
791
set_action_state("svncleanup", single_versioned_path, true);
793
single_ivle_versioned_path = (
795
(numsel == 1 && (stat = file_listing[selected_files[0]])) ||
796
(numsel == 0 && (stat = current_file))
797
) && stat.svnstatus != "unversioned"
799
&& stat.svnurl.substr(0, svn_base.length) == svn_base);
800
set_action_state(["submit"], single_ivle_versioned_path);
705
set_action_state(["svnadd", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
707
/* Diff and log only support one path at the moment. */
708
single_versioned_path = (numsel == 1 &&
709
(svnst = file_listing[selected_files[0]].svnstatus) &&
710
svnst != "unversioned");
711
set_action_state("svnlog", single_versioned_path);
712
set_action_state("svndiff", single_versioned_path && svnst != "normal");
714
/* current_path == username: We are at the top level */
715
set_action_state("svncheckout", current_path == username);
802
717
/* There is currently nothing on the More Actions menu of use
803
718
* when the current file is not a directory. Hence, just remove
811
726
var actions2_directory = document.getElementById("actions2_directory");
812
727
actions2_directory.setAttribute("style", "display: inline;");
813
var moreactions = document.getElementById("moreactions_area");
814
moreactions.setAttribute("style", "display: inline;");
818
731
var actions2_file = document.getElementById("actions2_file");
819
732
actions2_file.setAttribute("style", "display: inline;");
733
var moreactions = document.getElementById("moreactions_area");
734
moreactions.setAttribute("style", "display: none;");
853
768
action_unpublish(selected_files);
856
window.open(public_app_path("~" + current_path, filename), 'share')
771
//alert("Not yet implemented: Sharing files");
772
window.open(public_app_path(serve_app, current_path, filename), 'share')
859
if (selected_files.length == 1)
860
stat = file_listing[selected_files[0]];
863
path = stat.svnurl.substr(svn_base.length);
865
/* The working copy might not have an up-to-date version of the
866
* directory. While submitting like this could yield unexpected
867
* results, we should really submit the latest revision to minimise
868
* terrible mistakes - so we run off and ask fileservice for the
870
$.post(app_path(service_app, current_path),
871
{"action": "svnrepostat", "path": path},
874
window.location = path_join(app_path('+submit'), path) + '?revision=' + result.svnrevision;
776
alert("Not yet implemented: Submit");
880
779
action_rename(filename);
883
action_delete(selected_files);
782
action_remove(selected_files);
886
785
action_copy(selected_files);
904
803
action_add(selected_files);
907
action_remove(selected_files);
909
805
case "svnrevert":
910
806
action_revert(selected_files);
913
window.location = path_join(app_path('diff'), current_path, selected_files[0] || '');
916
action_update(selected_files);
919
action_resolved(selected_files);
809
window.location = path_join(app_path('diff'), current_path, selected_files[0]);
921
811
case "svncommit":
922
812
action_commit(selected_files);
925
window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
928
action_svncopy(selected_files);
931
action_svncut(selected_files);
934
action_svncleanup(".");
815
window.location = path_join(app_path('svnlog'), current_path, selected_files[0]);
960
844
* This causes the page to be populated with whatever is at that address,
961
845
* whether it be a directory or a file.
963
var path = get_path();
967
/** Gets the current path of the window */
968
function get_path() {
969
847
var path = parse_url(window.location.href).path;
970
848
/* Strip out root_dir + "/files" from the front of the path */
971
849
var strip = make_path(this_app);