changeset 13:1edbabcbcdbd

Cleanups, and AutoMove(tm) functionality.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Jan 2011 08:49:45 +0200
parents 774db3b4bedc
children 11f9c6fc4e6e
files index.php
diffstat 1 files changed, 83 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Mon Jan 10 08:12:23 2011 +0200
+++ b/index.php	Mon Jan 10 08:49:45 2011 +0200
@@ -243,7 +243,8 @@
 <!--  <input type="button" value=" Create TinyFugue Macros " onclick="createInit('tf');" /> 
 -->
   <input type="button" value=" Create SAVEBLOB " onclick="createInit('save');" />
-  <input type="button" value=" Reset " onclick="resetAll();" />
+  <input type="button" value=" Reset All " onclick="resetAll();" />
+  <input type="button" value=" Clear Containers " onclick="clearContainers();" />
  </p>
 
 
@@ -258,7 +259,8 @@
       <td><input type="button" value=" Delete " onclick="deleteItems(this.form);" /></td>
       <td><input type="button" value=" Add new " onclick="addItems(this.form);" disabled="disabled" /></td>
       <td><b><span id="curr_nitems"></span> items</b></td>
-      <td style="width: 60%; text-align: right;"><input id="move_button" type="button" value=" Move to container " onclick="moveItems(this.form);" /></td>
+      <td><input type="button" value=" AutoMove " onclick="autoMoveItems(this.form);" /></td>
+      <td style="width: 60%; text-align: right;"><input type="button" value=" Move to container " onclick="moveItems(this.form);" /></td>
      </tr>
     </table>
    </td>
@@ -283,7 +285,7 @@
 printInputField("container_slots", "Number of slots", 5);
  ?>
     <input type="button" value=" Create new " onclick="containerCreate(this.form);" id="create_button" />
-    <input type="button" value=" Change " onclick="containerChange(this.form);" id="change_button" />
+    <input type="button" value=" Modify " onclick="containerModify(this.form);" id="modify_button" />
    </td>
 
    <td id="container_list_editor">
@@ -413,14 +415,20 @@
 var list_containers;
 var list_items;
 
-function initAll()
+function initContainers()
 {
   list_containers = [".$str."];
+}
+
+function initItems()
+{
   list_items = ".(isset($data["items"]) ? getContainerObject("items", 10000, $data["items"]) : "null").";
+}
+
+function initSettings()
+{
 ".$jsData."
   curr_container = null;
-  updatePage();
-  statusMsg('Welcome to the editor. <b>(c) Copyright 2011 Matti H&auml;m&auml;l&auml;inen aka Ggr Pupunen.</b>');
 }
 ";
 ?>
@@ -429,12 +437,30 @@
 
 function resetAll()
 {
-  var answer = confirm("Really delete all defined containers and reset item pool to original state?");
+  var answer = confirm("Really delete all defined containers and reset item pool to original state? You will have to re-define containers from scratch.");
   if (!answer) {
     statusMsg("Reset operation cancelled.");
     return;
   }
-  initAll();
+  initContainers();
+  initItems();
+  initSettings();
+  updatePage();
+  statusMsg('Welcome to the editor. <b>(c) Copyright 2011 Matti H&auml;m&auml;l&auml;inen aka Ggr Pupunen.</b>');
+}
+
+function clearContainers()
+{
+  var answer = confirm("Really clear (empty) all defined containers and reset item pool to original state?");
+  if (!answer) {
+    statusMsg("Clear operation cancelled.");
+    return;
+  }
+  initItems();
+  for (var i = 0; i < list_containers.length; i++) {
+    list_containers[i].items = [];
+  }
+  updatePage();
 }
 
 
@@ -563,7 +589,7 @@
 
 
 // Change current container
-function containerChange(f)
+function containerModify(f)
 {
   if (curr_container == null) {
     statusMsg("No current container, create or select one.");
@@ -738,6 +764,49 @@
   }
 }
 
+function autoMoveItems(f)
+{
+  var selected = getSelectedItems(f.elements['curr_items']);
+  
+  if (selected.length == 0) {
+    statusMsg("No items selected for AutoMove(tm).");
+    return;
+  }
+
+  if (list_containers.length == 0) {
+    statusMsg("No containers available for AutoMove(tm).");
+    return;
+  }
+
+  var remaining = selected.length;
+  var n = 0;
+  while (remaining > 0 && n < list_containers.length) {
+    curr = list_containers[n];
+    
+    for (var q = curr.getSpace(); q > 0 && remaining > 0; q--) {
+      remaining--;
+      if (!list_items.moveItemById(curr, selected[remaining])) {	
+        statusMsg("Internal error moving item #"+remaining+": '"+selected[remaining]+"'.");
+        return;
+      }
+    }
+
+    n++;
+  }
+
+  list_items.flush();
+  updatePage();
+
+  if (remaining > 0) {
+    statusMsg("Not enough space! <b>"+ remaining +" of "+ selected.length +"</b> items left without slots!");
+    return;
+  }
+
+  statusMsg("AutoMoved " + selected.length + " items to containers.");
+}
+
+
+
 
 var edit_modes = ['batmud', 'tf', 'save'];
 
@@ -829,7 +898,11 @@
   o.innerHTML = str;
 }
 
-initAll();
+
+initContainers();
+initItems();
+initSettings();
+updatePage();
 -->
 </script>
 <?