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
748
615
var publish = document.getElementById("act_publish");
749
616
var submit = document.getElementById("act_submit");
750
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");
753
622
/* If this dir is already published, call it "Unpublish" */
754
623
if (file.published)
756
625
publish.setAttribute("value", "unpublish");
757
626
publish.setAttribute("title" ,"Make it so this directory "
758
627
+ "can not be seen by anyone on the web");
759
publish.firstChild.nodeValue = "Unpublish";
628
publish.textContent = "Unpublish";
761
630
publish.setAttribute("value", "publish");
762
631
publish.setAttribute("title","Make it so this directory "
763
632
+ "can be seen by anyone on the web");
764
publish.firstChild.nodeValue = "Publish";
633
publish.textContent = "Publish";
767
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");
770
/* If exactly 1 non-directory file is selected, and its parent
647
/* If exactly 1 non-directory file is selected/opened, and its parent
771
648
* directory is published.
773
set_action_state("share", numsel == 1 && !file.isdir &&
774
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");
777
671
/* If exactly 1 file is selected */
778
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");
780
684
/* Delete, cut, copy */
781
685
/* If >= 1 file is selected */
782
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");
784
708
/* Paste, new file, new directory, upload */
785
709
/* Disable if the current file is not a directory */
786
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");
788
726
/* 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);
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");
828
753
/* There is currently nothing on the More Actions menu of use
829
754
* when the current file is not a directory. Hence, just remove
831
756
* (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)
758
if (!(current_file.isdir))
837
var actions2_directory = document.getElementById("actions2_directory");
838
actions2_directory.setAttribute("style", "display: inline;");
839
760
var moreactions = document.getElementById("moreactions_area");
840
moreactions.setAttribute("style", "display: inline;");
844
var actions2_file = document.getElementById("actions2_file");
845
actions2_file.setAttribute("style", "display: inline;");
761
moreactions.setAttribute("style", "display: none;");