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
146
/* Note: This header (in particular) comes URI-encoded, to
154
147
* allow multi-line error messages. Decode */
155
148
alert("Error: " + decodeURIComponent(error.toString()) + ".");
156
149
/* Now read the response and set up the page accordingly */
157
if (callback != null)
158
callback(path, response);
150
if (ignore_response != true)
151
handle_response(path, response, true);
160
153
/* Call the server and perform the action. This mutates the server. */
161
ajax_call(callback_inner, service_app, path, args, "POST", content_type);
154
ajax_call(callback, service_app, path, args, "POST", content_type);
164
157
/** Calls the server using Ajax, requesting a directory listing. This should
749
615
var publish = document.getElementById("act_publish");
750
616
var submit = document.getElementById("act_submit");
751
var pubcond = numsel <= 1 && file.isdir;
617
if (numsel <= 1 && file.isdir)
619
/* TODO: Work out of file is svn'd */
620
publish.setAttribute("class", "choice");
621
publish.removeAttribute("disabled");
754
622
/* If this dir is already published, call it "Unpublish" */
755
623
if (file.published)
757
625
publish.setAttribute("value", "unpublish");
758
626
publish.setAttribute("title" ,"Make it so this directory "
759
627
+ "can not be seen by anyone on the web");
760
publish.firstChild.nodeValue = "Unpublish";
628
publish.textContent = "Unpublish";
762
630
publish.setAttribute("value", "publish");
763
631
publish.setAttribute("title","Make it so this directory "
764
632
+ "can be seen by anyone on the web");
765
publish.firstChild.nodeValue = "Publish";
633
publish.textContent = "Publish";
768
set_action_state(["publish", "submit"], pubcond);
635
submit.setAttribute("class", "choice");
636
submit.removeAttribute("disabled");
640
publish.setAttribute("class", "disabled");
641
publish.setAttribute("disabled", "disabled");
642
submit.setAttribute("class", "disabled");
643
submit.setAttribute("disabled", "disabled");
771
/* If exactly 1 non-directory file is selected, and its parent
647
/* If exactly 1 non-directory file is selected/opened, and its parent
772
648
* directory is published.
774
set_action_state("share", numsel == 1 && !file.isdir &&
775
current_file.published);
650
var share = document.getElementById("act_share");
651
if (numsel <= 1 && !file.isdir)
653
/* Work out if parent dir is published */
654
parentdir = current_file;
655
if (parentdir.published)
657
share.setAttribute("class", "choice");
658
share.removeAttribute("disabled");
660
share.setAttribute("class", "disabled");
661
share.setAttribute("disabled", "disabled");
666
share.setAttribute("class", "disabled");
667
share.setAttribute("disabled", "disabled");
778
671
/* If exactly 1 file is selected */
779
set_action_state("rename", numsel == 1);
672
var rename = document.getElementById("act_rename");
675
rename.setAttribute("class", "choice");
676
rename.removeAttribute("disabled");
680
rename.setAttribute("class", "disabled");
681
rename.setAttribute("disabled", "disabled");
781
684
/* Delete, cut, copy */
782
685
/* If >= 1 file is selected */
783
set_action_state(["delete", "cut", "copy"], numsel >= 1);
686
var act_delete = document.getElementById("act_delete");
687
var cut = document.getElementById("act_cut");
688
var copy = document.getElementById("act_copy");
691
act_delete.setAttribute("class", "choice");
692
act_delete.removeAttribute("disabled");
693
cut.setAttribute("class", "choice");
694
cut.removeAttribute("disabled");
695
copy.setAttribute("class", "choice");
696
copy.removeAttribute("disabled");
700
act_delete.setAttribute("class", "disabled");
701
act_delete.setAttribute("disabled", "disabled");
702
cut.setAttribute("class", "disabled");
703
cut.setAttribute("disabled", "disabled");
704
copy.setAttribute("class", "disabled");
705
copy.setAttribute("disabled", "disabled");
785
708
/* Paste, new file, new directory, upload */
786
709
/* Disable if the current file is not a directory */
787
set_action_state(["paste", "newfile", "mkdir", "upload"], current_file.isdir);
710
if (!current_file.isdir)
712
var paste = document.getElementById("act_paste");
713
var newfile = document.getElementById("act_newfile");
714
var mkdir = document.getElementById("act_mkdir");
715
var upload = document.getElementById("act_upload");
716
paste.setAttribute("class", "disabled");
717
paste.setAttribute("disabled", "disabled");
718
newfile.setAttribute("class", "disabled");
719
newfile.setAttribute("disabled", "disabled");
720
mkdir.setAttribute("class", "disabled");
721
mkdir.setAttribute("disabled", "disabled");
722
upload.setAttribute("class", "disabled");
723
upload.setAttribute("disabled", "disabled");
789
726
/* Subversion actions */
790
/* These are only useful if we are in a versioned directory and have some
792
set_action_state(["svnrename"], numsel == 1 && current_file.svnstatus);
793
set_action_state(["svnadd"], numsel >= 1 && current_file.svnstatus);
794
/* And these are only useful is ALL the selected files are versioned */
795
set_action_state(["svnremove", "svnrevert", "svncopy", "svncut"],
796
numsel >= 1 && current_file.svnstatus && svn_selection);
797
/* Commit is useful if ALL selected files are versioned, or the current
798
* directory is versioned */
799
set_action_state(["svncommit"], current_file.svnstatus &&
800
(numsel >= 1 && svn_selection || numsel == 0));
802
/* Diff, log and update only support one path at the moment, so we must
803
* have 0 or 1 versioned files selected. If 0, the directory must be
805
single_versioned_path = (
807
(numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
808
(numsel == 0 && (svnst = current_file.svnstatus))
809
) && svnstatus_versioned(svnst));
810
set_action_state(["svndiff", "svnupdate"], single_versioned_path);
812
/* We can resolve if we have a file selected and it is conflicted. */
813
set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
815
/* Log should be available for revisions as well. */
816
set_action_state("svnlog", single_versioned_path, true);
818
/* Cleanup should be available for revisions as well. */
819
set_action_state("svncleanup", single_versioned_path, true);
821
single_ivle_versioned_path = (
823
(numsel == 1 && (stat = file_listing[selected_files[0]])) ||
824
(numsel == 0 && (stat = current_file))
825
) && svnstatus_versioned(stat.svnstatus)
827
&& stat.svnurl.substr(0, svn_base.length) == svn_base);
828
set_action_state(["submit"], single_ivle_versioned_path);
727
/* TODO: Work out when these are appropriate */
728
var svnadd = document.getElementById("act_svnadd");
729
var svnrevert = document.getElementById("act_svnrevert");
730
var svncommit = document.getElementById("act_svncommit");
733
svnadd.setAttribute("class", "choice");
734
svnadd.removeAttribute("disabled");
735
svnrevert.setAttribute("class", "choice");
736
svnrevert.removeAttribute("disabled");
737
svncommit.setAttribute("class", "choice");
738
svncommit.removeAttribute("disabled");
740
var svncheckout = document.getElementById("act_svncheckout");
741
/* current_path == username: We are at the top level */
742
if (current_path == username)
744
svncheckout.setAttribute("class", "choice");
745
svncheckout.removeAttribute("disabled");
749
svncheckout.setAttribute("class", "disabled");
750
svncheckout.setAttribute("disabled", "disabled");
830
753
/* There is currently nothing on the More Actions menu of use
831
754
* when the current file is not a directory. Hence, just remove
833
756
* (This makes some of the above decisions somewhat redundant).
834
* We also take this opportunity to show the appropriate actions2
835
* bar for this path. It should either be a save or upload widget.
837
if (current_file.isdir)
758
if (!(current_file.isdir))
839
var actions2_directory = document.getElementById("actions2_directory");
840
actions2_directory.setAttribute("style", "display: inline;");
841
760
var moreactions = document.getElementById("moreactions_area");
842
moreactions.setAttribute("style", "display: inline;");
846
var actions2_file = document.getElementById("actions2_file");
847
actions2_file.setAttribute("style", "display: inline;");
761
moreactions.setAttribute("style", "display: none;");