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",
87
87
default_svn_icon = null;
88
88
default_svn_nice = "Unknown status";
90
svn_icons_path = "+media/ivle.webapp.core/images/svn";
90
svn_icons_path = "media/images/svn";
92
published_icon = "+media/ivle.webapp.core/images/interface/published.png";
92
published_icon = "media/images/interface/published.png";
94
94
/* List of MIME types considered "executable" by the system.
95
95
* Executable files offer a "run" link, implying that the "serve"
134
134
* May be "application/x-www-form-urlencoded" or "multipart/form-data".
135
135
* Defaults to "application/x-www-form-urlencoded".
136
136
* "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)
138
function do_action(action, path, args, content_type, ignore_response)
142
140
args.action = action;
143
141
/* Callback action, when the server returns */
144
var callback_inner = function(response)
142
var callback = function(response)
146
144
/* Check for action errors reported by the server, and report them
148
146
var error = response.getResponseHeader("X-IVLE-Action-Error");
149
if (error != null && error != "")
150
148
/* Note: This header (in particular) comes URI-encoded, to
151
149
* allow multi-line error messages. Decode */
152
150
alert("Error: " + decodeURIComponent(error.toString()) + ".");
153
151
/* Now read the response and set up the page accordingly */
154
if (callback != null)
155
callback(path, response);
152
if (ignore_response != true)
153
handle_response(path, response, true);
157
155
/* Call the server and perform the action. This mutates the server. */
158
ajax_call(callback_inner, service_app, path, args, "POST", content_type);
156
ajax_call(callback, service_app, path, args, "POST", content_type);
161
159
/** Calls the server using Ajax, requesting a directory listing. This should
379
377
upload_callback_count++;
380
378
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
380
document.getElementsByName('data')[0].value = '';
559
/* Updates the list of available actions based on files selected */
560
548
function update_actions()
563
551
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;
645
620
var run = document.getElementById("act_run");
647
if (numsel <= 1 && !file.isdir && file.type == "text/x-python"
648
&& current_file.svnstatus != 'revision')
622
if (!file.isdir && file.type == "text/x-python" && numsel <= 1
623
&& current_file.svnstatus != 'revision')
728
703
var pubcond = numsel <= 1 && file.isdir;
706
/* TODO: Work out of file is svn'd */
731
707
/* If this dir is already published, call it "Unpublish" */
732
708
if (file.published)
734
710
publish.setAttribute("value", "unpublish");
735
711
publish.setAttribute("title" ,"Make it so this directory "
736
712
+ "can not be seen by anyone on the web");
737
publish.firstChild.nodeValue = "Unpublish";
713
publish.textContent = "Unpublish";
739
715
publish.setAttribute("value", "publish");
740
716
publish.setAttribute("title","Make it so this directory "
741
717
+ "can be seen by anyone on the web");
742
publish.firstChild.nodeValue = "Publish";
718
publish.textContent = "Publish";
745
721
set_action_state(["publish", "submit"], pubcond);
766
742
/* Subversion actions */
767
743
/* These are only useful if we are in a versioned directory and have some
768
744
* 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);
745
set_action_state(["svnadd", "svnremove", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
774
747
/* Diff, log and update only support one path at the moment, so we must
775
748
* have 0 or 1 versioned files selected. If 0, the directory must be
787
760
/* Log should be available for revisions as well. */
788
761
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);
802
763
/* There is currently nothing on the More Actions menu of use
803
764
* when the current file is not a directory. Hence, just remove
853
814
action_unpublish(selected_files);
856
window.open(public_app_path("~" + current_path, filename), 'share')
817
//alert("Not yet implemented: Sharing files");
818
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;
822
alert("Not yet implemented: Submit");
880
825
action_rename(filename);
960
896
* This causes the page to be populated with whatever is at that address,
961
897
* 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
899
var path = parse_url(window.location.href).path;
970
900
/* Strip out root_dir + "/files" from the front of the path */
971
901
var strip = make_path(this_app);