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
data = myFrame.firstChild.getElementsByTagName(
402
'body')[0].firstChild.firstChild.nodeValue;
403
data = JSON.parse(data);
405
alert("Error: " + decodeURIComponent(data['Error']));
406
380
document.getElementsByName('data')[0].value = '';
425
399
function maybe_save(warning)
427
401
if (warning == null) warning = '';
428
if (current_file == null || current_file.isdir) return true;
402
if (current_file.isdir) return true;
429
403
if (document.getElementById("save_button").disabled) return true;
430
404
return confirm("This file has unsaved changes. " + warning +
431
405
"\nAre you sure you wish to continue?");
528
502
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
505
/** Displays a download link to the binary file.
540
507
function handle_binary(path)
543
510
var div = document.createElement("div");
544
511
files.appendChild(div);
545
512
div.setAttribute("class", "padding");
546
var download_link = app_url(download_app, path);
513
var download_link = app_path(download_app, path);
547
514
var par1 = dom_make_text_elem("p",
548
515
"The file " + path + " is a binary file. To download this file, " +
549
516
"click the following link:");
581
/* Updates the list of available actions based on files selected */
582
548
function update_actions()
585
551
var numsel = selected_files.length;
586
var svn_selection = false;
590
svn_selection = true;
591
for (var i = 0; i < selected_files.length; i++){
592
if (!svnstatus_versioned(file_listing[selected_files[i]].svnstatus))
594
svn_selection = false;
648
601
"return maybe_save('The last saved version will be served.')");
650
603
serve.setAttribute("href",
651
app_url(serve_app, current_path));
604
app_path(serve_app, current_path));
653
606
serve.setAttribute("href",
654
app_url(serve_app, current_path, filename));
607
app_path(serve_app, current_path, filename));
667
620
var run = document.getElementById("act_run");
669
if (numsel <= 1 && !file.isdir && file.type == "text/x-python"
670
&& current_file.svnstatus != 'revision')
622
if (!file.isdir && file.type == "text/x-python" && numsel <= 1
623
&& current_file.svnstatus != 'revision')
709
662
download.setAttribute("href",
710
app_url(download_app, current_path));
663
app_path(download_app, current_path));
712
665
download.setAttribute("title",
713
666
"Download the current directory as a ZIP file");
720
673
download.setAttribute("href",
721
app_url(download_app, current_path, filename));
674
app_path(download_app, current_path, filename));
723
676
download.setAttribute("title",
724
677
"Download the selected directory as a ZIP file");
732
685
/* Make a query string with all the files to download */
733
var dlpath = app_url(download_app, current_path) + "?";
686
var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
734
687
for (var i=0; i<numsel; i++)
735
688
dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
736
689
dlpath = dlpath.substr(0, dlpath.length-1);
750
703
var pubcond = numsel <= 1 && file.isdir;
706
/* TODO: Work out of file is svn'd */
753
707
/* If this dir is already published, call it "Unpublish" */
754
708
if (file.published)
756
710
publish.setAttribute("value", "unpublish");
757
711
publish.setAttribute("title" ,"Make it so this directory "
758
712
+ "can not be seen by anyone on the web");
759
publish.firstChild.nodeValue = "Unpublish";
713
publish.textContent = "Unpublish";
761
715
publish.setAttribute("value", "publish");
762
716
publish.setAttribute("title","Make it so this directory "
763
717
+ "can be seen by anyone on the web");
764
publish.firstChild.nodeValue = "Publish";
718
publish.textContent = "Publish";
767
721
set_action_state(["publish", "submit"], pubcond);
788
742
/* Subversion actions */
789
743
/* These are only useful if we are in a versioned directory and have some
790
744
* 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));
745
set_action_state(["svnadd", "svnremove", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
800
747
/* Diff, log and update only support one path at the moment, so we must
801
748
* have 0 or 1 versioned files selected. If 0, the directory must be
805
752
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
806
753
(numsel == 0 && (svnst = current_file.svnstatus))
807
) && svnstatus_versioned(svnst));
754
) && svnst != "unversioned");
808
755
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
810
757
/* We can resolve if we have a file selected and it is conflicted. */
813
760
/* Log should be available for revisions as well. */
814
761
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
763
/* There is currently nothing on the More Actions menu of use
829
764
* when the current file is not a directory. Hence, just remove
879
814
action_unpublish(selected_files);
882
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')
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;
822
alert("Not yet implemented: Submit");
907
825
action_rename(filename);
937
855
action_revert(selected_files);
940
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] || '');
942
860
case "svnupdate":
943
861
action_update(selected_files);
949
867
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(".");
870
window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
987
896
* This causes the page to be populated with whatever is at that address,
988
897
* 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
899
var path = parse_url(window.location.href).path;
997
900
/* Strip out root_dir + "/files" from the front of the path */
998
901
var strip = make_path(this_app);