# HG changeset patch # User Matti Hamalainen # Date 1294642185 -7200 # Node ID 1edbabcbcdbdfa2a6da0865fcae08545b45bc533 # Parent 774db3b4bedc380fe46d5bbc6ac6903143591b40 Cleanups, and AutoMove(tm) functionality. diff -r 774db3b4bedc -r 1edbabcbcdbd index.php --- 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 @@ - + +

@@ -258,7 +259,8 @@ items - + + @@ -283,7 +285,7 @@ printInputField("container_slots", "Number of slots", 5); ?> - + @@ -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. (c) Copyright 2011 Matti Hämäläinen aka Ggr Pupunen.'); } "; ?> @@ -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. (c) Copyright 2011 Matti Hämäläinen aka Ggr Pupunen.'); +} + +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! "+ remaining +" of "+ selected.length +" 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(); -->