- remove debug prefix from set_subfile_prio command
- do not reload page when toggling subfiles (ajax)
---
 src/daemon/common/commonMessages.ml      |   26 ++++++++++++++++++++++++++
 src/daemon/driver/driverCommands.ml      |   11 ++++++-----
 src/daemon/driver/driverControlers.ml    |    5 +++++
 src/networks/bittorrent/bTInteractive.ml |    4 ++--
 4 files changed, 39 insertions(+), 7 deletions(-)

diff --git src/daemon/common/commonMessages.ml src/daemon/common/commonMessages.ml
index 7896b5d..41d6a93 100644
--- src/daemon/common/commonMessages.ml
+++ src/daemon/common/commonMessages.ml
@@ -621,6 +621,32 @@ function track_changed(obj)
     obj.className = obj.className.replace(/\\bchanged\\b/,'');
 }
 
+function xhr_ok_handler(f) {
+ return function() {
+// alert(this.readyState);
+   if (this.readyState != 4) return;
+   if (this.status == 200) { f(this.responseText); }
+ }
+}
+
+function xhr_get(url,f) {
+var client = new XMLHttpRequest();
+client.onreadystatechange = xhr_ok_handler(f);
+client.open(\"GET\", url);
+client.send();
+}
+
+function toggle_priority(o,file,sub)
+{
+  return function(prio) {
+    var p = \"0\";
+    if (prio == \"0\") p = \"1\";
+    o.onclick = function() {
+      xhr_get(\"submit?api=set_subfile_prio+\"+file+\"+\"+p+\"+\"+sub, toggle_priority(o,file,sub)); };
+    o.innerText = \"priority \"+prio;
+  }
+}
+
 //-->
   "
 
diff --git src/daemon/driver/driverCommands.ml src/daemon/driver/driverCommands.ml
index 105fb6f..1878cff 100644
--- src/daemon/driver/driverCommands.ml
+++ src/daemon/driver/driverCommands.ml
@@ -3924,9 +3924,8 @@ let _ =
            "";
     ), ":\t\t\t\t\tget file block priorities for a file, and show subfile completion status";
 
-    "debug_set_subfile_prio", Arg_multiple 
+    "set_subfile_prio", Arg_multiple 
       (fun args o ->
-        let buf = o.conn_buf in
         match args with
         | filenum :: priochar :: subfilestart :: q ->
             let filenum = int_of_string filenum in
@@ -3951,14 +3950,16 @@ let _ =
               subfile_pos subfile2 ++ subfile_len subfile2 
 (*                 -- if subfile_len subfile2 > 0L then 1L else 0L  *)
             in
+(*
             Printf.bprintf buf "file %s\nstart %Ld stop %Ld prio %u\n" 
               swarmer.CommonSwarming.s_filename start stop priochar;
+*)
             CommonSwarming.swarmer_set_interval swarmer (start,stop,priochar);
             (* show file *)
-            execute_command !CommonNetwork.network_commands o "vd" [string_of_int filenum];
-            ""
+(*             execute_command !CommonNetwork.network_commands o "vd" [string_of_int filenum]; *)
+            string_of_int priochar
         | _ -> bad_number_of_args "" ""
-    ), "debug_set_subfile_prio <download id> <prio> <1st subfile> <optional last subfile>";
+    ), "set_subfile_prio <download id> <prio> <1st subfile (0-based)> <optional last subfile>";
 
     "reload_messages", Arg_none (fun o ->
         CommonMessages.load_message_file ();
diff --git src/daemon/driver/driverControlers.ml src/daemon/driver/driverControlers.ml
index 8ed3b96..6f59833 100644
--- src/daemon/driver/driverControlers.ml
+++ src/daemon/driver/driverControlers.ml
@@ -1402,6 +1402,11 @@ let http_handler o t r =
                   html_open_page buf t r true;
                   send_custom_query o.conn_user buf query args
 
+              | [ ("api", cmd) ] ->
+                  clear_page o.conn_buf;
+                  eval (ref true) cmd o;
+                  Buffer.add_string buf (Buffer.contents o.conn_buf)
+
               | [ "setoption", _ ; "option", name; "value", value ] ->
                   html_open_page buf t r true;
                   let gui_type, ip, port =
diff --git src/networks/bittorrent/bTInteractive.ml src/networks/bittorrent/bTInteractive.ml
index 9928e25..1f74cbf 100644
--- src/networks/bittorrent/bTInteractive.ml
+++ src/networks/bittorrent/bTInteractive.ml
@@ -409,7 +409,7 @@ let op_file_print file o =
     with
     | None -> ""
     | Some dl ->
-      Printf.sprintf ", \\<a title=\\\"toggle all files\\\" href=\\\"submit?q=debug_set_subfile_prio+%d+%d+%d+%d\\\"\\>%s\\</a\\>"
+      Printf.sprintf ", \\<a title=\\\"toggle all files\\\" href=\\\"submit?q=set_subfile_prio+%d+%d+%d+%d\\\"\\>%s\\</a\\>"
         (file_num file) (if dl then 0 else 1) 0 (List.length subfiles - 1)
         (if dl then "unselect all" else "select all")
   in
@@ -421,7 +421,7 @@ let op_file_print file o =
     let fs = Printf.sprintf (_b"File %d") !cntr in
     let extra = match prio with
       | None -> ""
-      | Some prio -> Printf.sprintf ", \\<a title=\\\"toggle file\\\" href=\\\"submit?q=debug_set_subfile_prio+%d+%d+%d\\\"\\>priority %d\\</a\\>" (file_num file) (if prio = 0 then 1 else 0) !cntr prio
+      | Some prio -> Printf.sprintf ", \\<a title=\\\"toggle file\\\" href=\\\"javascript:void(0)\\\" onclick=\\\"xhr_get('submit?api=set_subfile_prio+%d+%d+%d',toggle_priority(this,%d,%d))\\\"\\>priority %d\\</a\\>" (file_num file) (if prio = 0 then 1 else 0) !cntr (file_num file) !cntr prio
     in
     emit (fs^extra) ~desc:fs (Printf.sprintf "%s (%Ld bytes%s)%s" filename size progress magic);
     incr cntr;
-- 
1.7.2.5
