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
data = myFrame.firstChild.getElementsByTagName(
402
'body')[0].firstChild.firstChild.nodeValue;
381
data = myFrame.firstChild.childNodes[1].firstChild.firstChild.nodeValue;
403
382
data = JSON.parse(data);
404
383
if ('Error' in data)
405
384
alert("Error: " + decodeURIComponent(data['Error']));
425
404
function maybe_save(warning)
427
406
if (warning == null) warning = '';
428
if (current_file == null || current_file.isdir) return true;
407
if (current_file.isdir) return true;
429
408
if (document.getElementById("save_button").disabled) return true;
430
409
return confirm("This file has unsaved changes. " + warning +
431
410
"\nAre you sure you wish to continue?");
528
507
return default_svn_nice;
531
/** Returns true if a file is versioned (not unversioned or ignored).
533
function svnstatus_versioned(svnstatus)
535
return svnstatus != "unversioned" && svnstatus != "ignored";
538
510
/** Displays a download link to the binary file.
540
512
function handle_binary(path)
543
515
var div = document.createElement("div");
544
516
files.appendChild(div);
545
517
div.setAttribute("class", "padding");
546
var download_link = app_url(download_app, path);
518
var download_link = app_path(download_app, path);
547
519
var par1 = dom_make_text_elem("p",
548
520
"The file " + path + " is a binary file. To download this file, " +
549
521
"click the following link:");
648
620
"return maybe_save('The last saved version will be served.')");
650
622
serve.setAttribute("href",
651
app_url(serve_app, current_path));
623
app_path(serve_app, current_path));
653
625
serve.setAttribute("href",
654
app_url(serve_app, current_path, filename));
626
app_path(serve_app, current_path, filename));
709
681
download.setAttribute("href",
710
app_url(download_app, current_path));
682
app_path(download_app, current_path));
712
684
download.setAttribute("title",
713
685
"Download the current directory as a ZIP file");
720
692
download.setAttribute("href",
721
app_url(download_app, current_path, filename));
693
app_path(download_app, current_path, filename));
723
695
download.setAttribute("title",
724
696
"Download the selected directory as a ZIP file");
732
704
/* Make a query string with all the files to download */
733
var dlpath = app_url(download_app, current_path) + "?";
705
var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
734
706
for (var i=0; i<numsel; i++)
735
707
dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
736
708
dlpath = dlpath.substr(0, dlpath.length-1);
756
728
publish.setAttribute("value", "unpublish");
757
729
publish.setAttribute("title" ,"Make it so this directory "
758
730
+ "can not be seen by anyone on the web");
759
publish.firstChild.nodeValue = "Unpublish";
731
publish.textContent = "Unpublish";
761
733
publish.setAttribute("value", "publish");
762
734
publish.setAttribute("title","Make it so this directory "
763
735
+ "can be seen by anyone on the web");
764
publish.firstChild.nodeValue = "Publish";
736
publish.textContent = "Publish";
767
739
set_action_state(["publish", "submit"], pubcond);
788
760
/* Subversion actions */
789
761
/* These are only useful if we are in a versioned directory and have some
790
762
* 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));
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);
800
768
/* Diff, log and update only support one path at the moment, so we must
801
769
* have 0 or 1 versioned files selected. If 0, the directory must be
805
773
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
806
774
(numsel == 0 && (svnst = current_file.svnstatus))
807
) && svnstatus_versioned(svnst));
775
) && svnst != "unversioned");
808
776
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
810
778
/* We can resolve if we have a file selected and it is conflicted. */
813
781
/* Log should be available for revisions as well. */
814
782
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);
828
784
/* There is currently nothing on the More Actions menu of use
829
785
* when the current file is not a directory. Hence, just remove
879
835
action_unpublish(selected_files);
882
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')
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;
843
alert("Not yet implemented: Submit");
907
846
action_rename(filename);
937
876
action_revert(selected_files);
940
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] || '');
942
881
case "svnupdate":
943
882
action_update(selected_files);
949
888
action_commit(selected_files);
952
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] || '');
955
894
action_svncopy(selected_files);
987
923
* This causes the page to be populated with whatever is at that address,
988
924
* whether it be a directory or a file.
990
var path = get_path();
994
/** Gets the current path of the window */
995
function get_path() {
996
926
var path = parse_url(window.location.href).path;
997
927
/* Strip out root_dir + "/files" from the front of the path */
998
928
var strip = make_path(this_app);