# HG changeset patch # User Matti Hamalainen # Date 1294636864 -7200 # Node ID da404b8ff282c7bc46f16bce3092e74bf61d6a16 # Parent 5e1cdf22d6472863cbd2ded12728e88bbcc236ae Container editing, persistent settings. diff -r 5e1cdf22d647 -r da404b8ff282 index.php --- a/index.php Mon Jan 10 06:58:14 2011 +0200 +++ b/index.php Mon Jan 10 07:21:04 2011 +0200 @@ -36,11 +36,22 @@ function printInputField($id, $label, $len, $value = "") { + global $jsData; + $jsData .= "document.getElementById(\"".$id."\").value = \"".$value."\";\n"; + echo "". "\n"; } +function printCheckBox($id, $label, $value = FALSE) +{ + global $jsData; + $jsData .= "document.getElementById(\"".$id."\").checked = ".($value ? "true" : "false").";\n"; + + echo "". + ""; +} function printOptionSelect($id, $size, $multi = FALSE) { @@ -264,7 +275,8 @@ printInputField("container_name", "Identifier/name", 15); printInputField("container_slots", "Number of slots", 5); ?> - + + @@ -274,7 +286,6 @@ - @@ -293,10 +304,8 @@

($1 = item, $2 = container)
- -
- -
+
+

@@ -401,6 +410,7 @@ { list_containers = [".$str."]; list_items = ".(isset($data["items"]) ? getContainerObject("items", 10000, $data["items"]) : "null")."; +".$jsData." updatePage(); } "; @@ -492,39 +502,69 @@ } -// Create a new container, set current container to it -function containerCreate(f) +function validateContainerData(f) { var name = f.elements['container_name'].value; var slots = parseInt(f.elements['container_slots'].value, 10); if (isNaN(slots) || slots < 1) { statusMsg("Number of slots not set or is invalid."); - return; + return null; } if (name == "") { statusMsg("Empty container name "+name+"."); - return; + return null; } if (name.match(/[^a-z0-9_]/)) { statusMsg("Invalid container name, only lower case alphanumerics and underscore are allowed."); - return; + return null; } + return {name: name, slots: slots}; +} + +// Create a new container, set current container to it +function containerCreate(f) +{ + var c = validateContainerData(f); + if (c == null) + return; + for (var i = 0; i < list_containers.length; i++) { - if (list_containers[i].name == name) { - statusMsg("Container with identifier '"+name+"' already exists!"); + if (list_containers[i].name == c.name) { + statusMsg("Container with identifier '"+c.name+"' already exists!"); return; } } - curr_container = new Container(name, slots, []); + curr_container = new Container(c.name, c.slots, []); list_containers.push(curr_container); clearForm(f); - statusMsg("OK, created new container '"+name+"' with "+slots+" slots."); + statusMsg("Created new container '"+c.name+"' with "+c.slots+" slots."); + updatePage(); +} + + +// Change current container +function containerChange(f) +{ + var c = validateContainerData(f); + if (c == null) + return; + + if (c.slots < curr_container.items.length) { + statusMsg("New number of slots can't be smaller than number of items in it! ("+ c.slots +" < "+ curr_container.items.length +")"); + return; + } + + curr_container.name = c.name; + curr_container.slots = c.slots; + + clearForm(f); + statusMsg("Updated container."); updatePage(); } @@ -591,6 +631,28 @@ } +function containerRemoveItems(f) +{ + if (curr_container == null) { + statusMsg("Internal error."); + return; + } + + var selected = getSelectedItems(f.elements['curr_container']); + + if (selected.length == 0) { + statusMsg("No items selected for deletion."); + return; + } else { + for (var i = 0; i < selected.length; i++) + curr_container.moveItemById(list_items, selected[i]); + + curr_container.flush(); + updatePage(); + statusMsg("Removed " + selected.length + " from current container."); + } +} + function getSelectedItems(items) { var selected = []; @@ -658,28 +720,6 @@ } -function containerRemoveItems(f) -{ - if (curr_container == null) { - statusMsg("Internal error."); - return; - } - - var selected = getSelectedItems(f.elements['curr_container']); - - if (selected.length == 0) { - statusMsg("No items selected for deletion."); - return; - } else { - for (var i = 0; i < selected.length; i++) - curr_container.moveItemById(list_items, selected[i]); - - curr_container.flush(); - updatePage(); - statusMsg("Removed " + selected.length + " from current container."); - } -} - var edit_modes = ['batmud', 'tf', 'save']; function createInit(mode)