137
132
* May be "application/x-www-form-urlencoded" or "multipart/form-data".
138
133
* Defaults to "application/x-www-form-urlencoded".
139
134
* "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)
136
function do_action(action, path, args, content_type, ignore_response)
145
138
args.action = action;
146
139
/* Callback action, when the server returns */
147
var callback_inner = function(response)
140
var callback = function(response)
149
142
/* Check for action errors reported by the server, and report them
151
144
var error = response.getResponseHeader("X-IVLE-Action-Error");
152
if (error != null && error != "")
153
/* Note: This header (in particular) comes URI-encoded, to
154
* allow multi-line error messages. Decode */
155
alert("Error: " + decodeURIComponent(error.toString()) + ".");
146
alert("Error: " + error.toString() + ".");
156
147
/* Now read the response and set up the page accordingly */
157
if (callback != null)
158
callback(path, response);
148
if (ignore_response != true)
149
handle_response(path, response);
160
151
/* Call the server and perform the action. This mutates the server. */
161
ajax_call(callback_inner, service_app, path, args, "POST", content_type);
152
ajax_call(callback, service_app, path, args, "POST", content_type);
164
155
/** Calls the server using Ajax, requesting a directory listing. This should
274
var err = document.createElement("div");
275
var p = dom_make_text_elem("p", "Error: "
276
+ "There was an unexpected server error processing "
277
+ "the selected command.");
279
p = dom_make_text_elem("p", "If the problem persists, please "
280
+ "contact the system administrator.")
282
p = document.createElement("p");
283
var refresh = document.createElement("input");
284
refresh.setAttribute("type", "button");
285
refresh.setAttribute("value", "Back to file view");
286
refresh.setAttribute("onclick", "refresh()");
287
p.appendChild(refresh);
293
var err = document.createElement("div");
294
var p = dom_make_text_elem("p", "Error: "
295
+ "There was an unexpected server error retrieving "
296
+ "the requested file or directory.");
298
p = dom_make_text_elem("p", "If the problem persists, please "
299
+ "contact the system administrator.")
247
handle_error("The server returned an invalid directory listing");
305
250
/* Get "." out, it's special */
306
251
current_file = file_listing["."]; /* Global */
307
252
delete file_listing["."];
309
if ('revision' in listing)
311
current_revision = listing.revision;
314
254
/* Check if this is a directory listing or file contents */
315
255
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);
258
handle_dir_listing(path, listing);
447
351
/*** HANDLERS for different types of responses (such as dir listing, file,
451
* message may either be a string, or a DOM node, which will be placed inside
454
354
function handle_error(message)
456
356
var files = document.getElementById("filesbody");
458
if (typeof(message) == "string")
460
txt_elem = dom_make_text_elem("div", "Error: "
461
+ message.toString() + ".")
465
/* Assume message is a DOM node */
466
txt_elem = document.createElement("div");
467
txt_elem.appendChild(message);
357
var txt_elem = dom_make_text_elem("div", "Error: "
358
+ message.toString() + ".")
469
359
txt_elem.setAttribute("class", "padding error");
470
360
files.appendChild(txt_elem);
473
/** Given a path, filename and optional revision, returns a URL to open that
474
* revision of that file.
476
function build_revision_url(path, filename, revision)
478
bits = {'path': app_path(this_app, path, filename)};
479
if (current_revision)
481
bits['query_string'] = 'r=' + revision;
483
return build_url(bits);
486
363
/** Given a mime type, returns the path to the icon.
487
364
* \param type String, Mime type.
488
365
* \param sizelarge Boolean, optional.
748
562
var publish = document.getElementById("act_publish");
749
563
var submit = document.getElementById("act_submit");
750
var pubcond = numsel <= 1 && file.isdir;
753
/* If this dir is already published, call it "Unpublish" */
756
publish.setAttribute("value", "unpublish");
757
publish.setAttribute("title" ,"Make it so this directory "
758
+ "can not be seen by anyone on the web");
759
publish.firstChild.nodeValue = "Unpublish";
761
publish.setAttribute("value", "publish");
762
publish.setAttribute("title","Make it so this directory "
763
+ "can be seen by anyone on the web");
764
publish.firstChild.nodeValue = "Publish";
767
set_action_state(["publish", "submit"], pubcond);
564
if (numsel <= 1 && file.isdir)
566
/* TODO: Work out of file is svn'd */
567
/* TODO: If this dir is already published, call it "Unpublish" */
568
publish.setAttribute("class", "choice");
569
publish.removeAttribute("disabled");
570
submit.setAttribute("class", "choice");
571
submit.removeAttribute("disabled");
575
publish.setAttribute("class", "disabled");
576
publish.setAttribute("disabled", "disabled");
577
submit.setAttribute("class", "disabled");
578
submit.setAttribute("disabled", "disabled");
770
/* If exactly 1 non-directory file is selected, and its parent
582
/* If exactly 1 non-directory file is selected/opened, and its parent
771
583
* directory is published.
773
set_action_state("share", numsel == 1 && !file.isdir &&
774
current_file.published);
585
var share = document.getElementById("act_share");
586
if (numsel <= 1 && !file.isdir)
588
/* TODO: Work out if parent dir is published */
589
share.setAttribute("class", "choice");
590
share.removeAttribute("disabled");
594
share.setAttribute("class", "disabled");
595
share.setAttribute("disabled", "disabled");
777
599
/* If exactly 1 file is selected */
778
set_action_state("rename", numsel == 1);
600
var rename = document.getElementById("act_rename");
603
rename.setAttribute("class", "choice");
604
rename.removeAttribute("disabled");
608
rename.setAttribute("class", "disabled");
609
rename.setAttribute("disabled", "disabled");
780
612
/* Delete, cut, copy */
781
613
/* If >= 1 file is selected */
782
set_action_state(["delete", "cut", "copy"], numsel >= 1);
614
var act_delete = document.getElementById("act_delete");
615
var cut = document.getElementById("act_cut");
616
var copy = document.getElementById("act_copy");
619
act_delete.setAttribute("class", "choice");
620
act_delete.removeAttribute("disabled");
621
cut.setAttribute("class", "choice");
622
cut.removeAttribute("disabled");
623
copy.setAttribute("class", "choice");
624
copy.removeAttribute("disabled");
628
act_delete.setAttribute("class", "disabled");
629
act_delete.setAttribute("disabled", "disabled");
630
cut.setAttribute("class", "disabled");
631
cut.setAttribute("disabled", "disabled");
632
copy.setAttribute("class", "disabled");
633
copy.setAttribute("disabled", "disabled");
784
636
/* Paste, new file, new directory, upload */
785
/* Disable if the current file is not a directory */
786
set_action_state(["paste", "newfile", "mkdir", "upload"], current_file.isdir);
637
/* Always enabled (assuming this is a directory) */
788
639
/* Subversion actions */
789
/* These are only useful if we are in a versioned directory and have some
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));
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
803
single_versioned_path = (
805
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
806
(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");
813
/* Log should be available for revisions as well. */
814
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
/* There is currently nothing on the More Actions menu of use
829
* when the current file is not a directory. Hence, just remove
831
* (This makes some of the above decisions somewhat redundant).
832
* We also take this opportunity to show the appropriate actions2
833
* bar for this path. It should either be a save or upload widget.
835
if (current_file.isdir)
837
var actions2_directory = document.getElementById("actions2_directory");
838
actions2_directory.setAttribute("style", "display: inline;");
839
var moreactions = document.getElementById("moreactions_area");
840
moreactions.setAttribute("style", "display: inline;");
640
/* TODO: Work out when these are appropriate */
641
var svnadd = document.getElementById("act_svnadd");
642
var svnrevert = document.getElementById("act_svnrevert");
643
var svncommit = document.getElementById("act_svncommit");
646
svnadd.setAttribute("class", "choice");
647
svnadd.removeAttribute("disabled");
648
svnrevert.setAttribute("class", "choice");
649
svnrevert.removeAttribute("disabled");
650
svncommit.setAttribute("class", "choice");
651
svncommit.removeAttribute("disabled");
653
var svncheckout = document.getElementById("act_svncheckout");
654
/* current_path == username: We are at the top level */
655
if (current_path == username)
657
svncheckout.setAttribute("class", "choice");
658
svncheckout.removeAttribute("disabled");
844
var actions2_file = document.getElementById("actions2_file");
845
actions2_file.setAttribute("style", "display: inline;");
662
svncheckout.setAttribute("class", "disabled");
663
svncheckout.setAttribute("disabled", "disabled");