Mercurial > hg > batmud > chester
annotate index.php @ 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 |
rev | line source |
---|---|
0 | 1 <? |
6 | 2 $pageTitle = "Pupunen BatMUD Container Command Creator ALPHA"; |
0 | 3 $pageIndex = "index.php"; |
4 require "mcommon.inc.php"; | |
5 | |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
6 |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
7 // Multi-stack item fixups |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
8 $fixItemTable = array( |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
9 "(purple|green) gloves" => 'a ${1} glove', |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
10 "heavy black metal rings" => "a heavy black metal ring", |
5 | 11 "bracelet mades of green crystal" => "bracelet made of green crystal", |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
12 "alchemist moulded rings" => "alchemist moulded ring", |
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
13 |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
14 "white cloth packs for holding salves" => "white cloth pack for holding salves", |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
15 "(small|HUGE) shiny boxes for storing minerals" => 'a ${1} shiny box for storing minerals', |
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
16 "(small|HUGE) sturdy packs for storing potions" => 'a ${1} sturdy pack for storing potions', |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
17 ); |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
18 |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
19 |
2 | 20 $fixNumbers = array( |
21 "one" => 1, "two" => 2, "three" => 3, "four" => 4, | |
22 "five" => 5, "six" => 6, "seven" => 7, "eight" => 8, | |
23 "nine" => 9, "ten" => 10 | |
24 ); | |
25 | |
26 | |
0 | 27 function getJSArraySegment($arr) |
28 { | |
29 $str = ""; | |
30 foreach ($arr as $item) { | |
31 if ($str != "") $str .= ", "; | |
32 if (is_array($item)) | |
33 $str .= "[".getJSArraySegment($item)."]"; | |
34 else | |
35 $str .= "\"".addslashes($item)."\""; | |
36 } | |
37 return $str; | |
38 } | |
39 | |
40 | |
2 | 41 function printInputField($id, $label, $len, $value = "") |
0 | 42 { |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
43 global $jsData; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
44 $jsData .= "document.getElementById(\"".$id."\").value = \"".$value."\";\n"; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
45 |
2 | 46 echo "<label for=\"".$id."\">".htmlentities($label).": </label>". |
47 "<input type=\"text\" name=\"".$id."\" maxlength=\"".$len. | |
48 "\" size=\"".$len."\" id=\"".$id."\" value=\"".htmlentities($value)."\" />\n"; | |
1 | 49 } |
50 | |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
51 function printCheckBox($id, $label, $value = FALSE) |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
52 { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
53 global $jsData; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
54 $jsData .= "document.getElementById(\"".$id."\").checked = ".($value ? "true" : "false").";\n"; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
55 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
56 echo "<input type=\"checkbox\" id=\"".$id."\" value=\"".$value."\" ".($value ? "checked=\"checked\"" : "")." />". |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
57 "<label for=\"".$id."\">".htmlentities($label)."</label>"; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
58 } |
1 | 59 |
60 function printOptionSelect($id, $size, $multi = FALSE) | |
61 { | |
62 echo "<select ".($multi ? " multiple=\"multiple\"" : "")." size=\"".$size."\" id=\"".$id."\"><option></option></select>"; | |
0 | 63 } |
64 | |
65 | |
2 | 66 if (isset($_POST["mode"])) { |
67 $formMode = intval($_POST["mode"]); | |
68 } else | |
69 $formMode = 0; | |
70 | |
71 | |
1 | 72 printPageHeader($pageTitle, " |
73 <style type=\"text/css\"> | |
74 <!-- | |
75 .buttons { width: 100%; } | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
76 select { width: 100%; } |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
77 |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
78 div.options, #commands, #status { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
79 background: #268; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
80 border: 1px solid white; |
11 | 81 color: white; |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
82 } |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
83 |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
84 div.options { display: none; position: fixed; top: 2em; left: 2em; padding: 1em; } |
2 | 85 |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
86 #commands { display: none; position: fixed; top: 2em; left: 2em; padding: 1em; z-index: 15; } |
1 | 87 |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
88 #status { position: absolute; bottom: 1em; right: 1em; left: 1em; padding: 2pt; z-index: -1; } |
1 | 89 --> |
90 </style> | |
91 "); | |
0 | 92 echo "<h1>".$pageTitle."</h1>\n"; |
93 | |
2 | 94 |
95 /* | |
96 * Initial mode, request item listing | |
97 */ | |
0 | 98 if ($formMode == 0) { |
99 ?> | |
100 <noscript> | |
2 | 101 <p> |
0 | 102 <b>This application REQUIRES JavaScript to be enabled!</b> |
2 | 103 </p> |
0 | 104 </noscript> |
105 <p> | |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
106 <form action"<? echo $pageIndex; ?>" method="post"> |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
107 <input type="hidden" value="YToxOntzOjU6Iml0ZW1zIjthOjQ3OntpOjA7czozODoiVGhlIHN0YWZmIG9mIExlcmV0aGluIGxhYmVsZWQgYXMgfEdncnwiO2k6MTtzOjM1OiJzd2lybGVkIGdyZWVuIHZlc3QgbGFiZWxlZCBhcyAoR2dyKSI7aToyO3M6Njk6ImEgd2VsbC1jcmFmdGVkIHBhaXIgb2Ygc3R1ZC1jb3ZlcmVkIGxlYXRoZXIgbGVnZ2luZ3MgbGFiZWxlZCBhcyAoR2dyKSI7aTozO3M6NTU6IlJpbmcgb2Ygd2lzZG9tIFtNYWRlIGJ5OiBOdWFuZV0gbGFiZWxlZCBhcyA2d2lzMWhwci9nZ3IiO2k6NDtzOjU0OiJzaGluaW5nIHJpbmcgY3JhZnRlZCBvdXQgb2YgbW9vbnN0b25lIGxhYmVsZWQgYXMgKEdncikiO2k6NTtzOjUxOiJHcmlteSBncmVhdCBjbG9hayBvZiB0cnVlIHNvcmNlcmVyIGxhYmVsZWQgYXMgfEdncnwiO2k6NjtzOjI5OiJhIGJsYWNrIGhvb2QgbGFiZWxlZCBhcyB8R2dyfCI7aTo3O3M6Mzg6InRoZSB0b21lIG9mIGtub3dsZWRnZSBsYWJlbGVkIGFzIChHZ3IpIjtpOjg7czo1MzoiaGVhdnkgdGFiYXJkIHdpdGggYSBjaGFsaWNlIGVuc2lnbmlhIGxhYmVsZWQgYXMgKEdncikiO2k6OTtzOjQ3OiJkYXJrIGdyZXkgYW5kIHdoaXRlIHBsYWlkIGtpbHQgbGFiZWxlZCBhcyAoR2dyKSI7aToxMDtzOjM4OiJzdHJvbmcgc2FwcGhpcmUgYm9vdHMgbGFiZWxlZCBhcyAoR2dyKSI7aToxMTtzOjI3OiJzdW4gYW11bGV0IGxhYmVsZWQgYXMgKEdncikiO2k6MTI7czo0MDoiQW5jaWVudCBCcmFjZXJzIG9mIFh6dWkgbGFiZWxlZCBhcyAoR2dyKSI7aToxMztzOjQyOiJnbGl0dGVyaW5nIGxlZyBwcm90ZWN0b3JzIGxhYmVsZWQgYXMgKEdncikiO2k6MTQ7czo0OToiYSBicmFjZWxldCBtYWRlIG9mIGdyZWVuIGNyeXN0YWwgbGFiZWxlZCBhcyAoR2dyKSI7aToxNTtzOjQ5OiJhIGJyYWNlbGV0IG1hZGUgb2YgZ3JlZW4gY3J5c3RhbCBsYWJlbGVkIGFzIChHZ3IpIjtpOjE2O3M6NDU6ImEgcmVpbmZvcmNlZCBicm9uemUgYnJhY2VsZXQgbGFiZWxlZCBhcyAoR2dyKSI7aToxNztzOjQyOiJ0aGUgQnJhY2VsZXRzIG9mIERhcmtuZXNzIGxhYmVsZWQgYXMgKEdncikiO2k6MTg7czozNDoiVGlidXJjaW8ncyBhbXVsZXQgbGFiZWxlZCBhcyAoR2dyKSI7aToxOTtzOjQ5OiJuZWNrbGFjZSBtYWRlIG91dCBvZiBzaGFycCBmYW5ncyBsYWJlbGVkIGFzIChHZ3IpIjtpOjIwO3M6NjI6ImEgZ2xpbW1lcmluZyBsZWF0aGVyIGJlbHQgd2l0aCBnZW0gZGVjb3JhdGlvbiBsYWJlbGVkIGFzIChHZ3IpIjtpOjIxO3M6NDE6ImEgaGVhdnkgYmxhY2sgbWV0YWwgcmluZyBsYWJlbGVkIGFzIChHZ3IpIjtpOjIyO3M6NDE6ImEgaGVhdnkgYmxhY2sgbWV0YWwgcmluZyBsYWJlbGVkIGFzIChHZ3IpIjtpOjIzO3M6NDU6IkRlbW9uaWMgUmluZyBvZiBJbnZpc2liaWxpdHkgbGFiZWxlZCBhcyAoR2dyKSI7aToyNDtzOjMxOiJhIHB1cnBsZSBnbG92ZSBsYWJlbGVkIGFzIChHZ3IpIjtpOjI1O3M6MzE6ImEgcHVycGxlIGdsb3ZlIGxhYmVsZWQgYXMgKEdncikiO2k6MjY7czozMDoiYSBncmVlbiBnbG92ZSBsYWJlbGVkIGFzIChHZ3IpIjtpOjI3O3M6MzA6ImEgZ3JlZW4gZ2xvdmUgbGFiZWxlZCBhcyAoR2dyKSI7aToyODtzOjQzOiJhIHBhaXIgb2YgYmxhY2sgYm9vdHMgbGFiZWxlZCBhcyB8R2dyTXVycml8IjtpOjI5O3M6NzI6IkEgYmVhdXRpZnVsIHJvc2FyeSBlbmZvbGRlZCB3aXRoIHdoaXRlIG1pc3QgbGFiZWxlZCBhcyB8R2dyTXVycml8IChob2x5KSI7aTozMDtzOjgyOiJhIHNtYWxsIHJpbmcgYmVhcmluZyB0aGUgZW1ibGVtIG9mIHRoZSBidW5ueSBbTWFkZSBieTogS2lvbWV0XSBsYWJlbGVkIGFzIDZ3aXMyaW50IjtpOjMxO3M6NjE6ImEgdmlhbCBjb250YWluaW5nIHRoZSB0ZWFycyBvZiBPeHRvdGggbGFiZWxlZCBhcyAoR2dyKSAoaG9seSkiO2k6MzI7czo0NDoiQSBsZWF0aGVyIHBvdWNoIGxhYmVsZWQgYXMgdjQgKHF1YXJ0ZXIgZnVsbCkiO2k6MzM7czo0Mzoic2xlZXZlcyBvZiBtb29taW4gZW11bHNpb24gbGFiZWxlZCBhcyAoR2dyKSI7aTozNDtzOjMzOiJhIGdyZWVuIGhlYWRiYW5kIGxhYmVsZWQgYXMgKEdncikiO2k6MzU7czozNDoiQ2FwZSBvZiBLbm93bGVkZ2UgbGFiZWxlZCBhcyAoR2dyKSI7aTozNjtzOjU0OiJUaGUgZ2xlYW1pbmcgYmx1ZSBjb2xsYXIgb2YgQmVuZ2Fsb3JlIGxhYmVsZWQgYXMgKEdncikiO2k6Mzc7czo1MToiZ29sZGVuIGJlbHQgb2YgRmFpciBSaXZlci1EYXVnaHRlciBsYWJlbGVkIGFzIChHZ3IpIjtpOjM4O3M6NDI6ImEgYmxhY2sgY2xvYWsgKGV2aWwgZ2xvdykgbGFiZWxlZCBhcyB8R2dyfCI7aTozOTtzOjM1OiJSaW5nIG9mIHRoZSBNZWR1c2EgbGFiZWxlZCBhcyAoR2dyKSI7aTo0MDtzOjQ0OiJBIGxvdyB3aWRlLWJyaW1tZWQgaGF0IGxhYmVsZWQgYXMgfEdnck11cnJpfCI7aTo0MTtzOjEzOiJhIHN0ZXRob3Njb3BlIjtpOjQyO3M6NjY6ImEgc2hpbW1lcmluZyBibHVlIGJyZWFzdHBsYXRlIG1hZGUgb2YgcXVhcnR6IGxhYmVsZWQgYXMgfEdnck11cnJpfCI7aTo0MztzOjUzOiJhIHBhaXIgb2YgcHVyZSB3aGl0ZSBmbG93aW5nIHNsZWV2ZXMgbGFiZWxlZCBhcyAoR2dyKSI7aTo0NDtzOjQzOiJSZWRmYW5nIEJlYWRzIG9mIElyb24gV2lsbCBsYWJlbGVkIGFzIChHZ3IpIjtpOjQ1O3M6NTk6Ik5vdmEgQXJjYW51bSwgTWVsa2lvcidzIGJvb2sgb2YgbmVjcm9tYW5jeSBsYWJlbGVkIGFzIChHZ3IpIjtpOjQ2O3M6NDQ6ImEgcGFpciBvZiBzaG9ydCBncmVlbiBib290cyBsYWJlbGVkIGFzIChHZ3IpIjt9fQ==" name="data" /> |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
108 <input type="hidden" value="2" name="mode" /> |
0 | 109 First, you should provide a list of equipments you wish to manage. |
110 Just plain copy & paste of an inventory listing is enough. | |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
111 You can also test with pre-defined equipments, |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
112 <input type="submit" value=" Test " /> by clicking the button. |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
113 </form> |
0 | 114 </p> |
115 <p> | |
116 <b>Stacks of items are not supported, and few other things may cause problems too.</b> | |
117 </p> | |
118 <form action="<? echo $pageIndex; ?>" method="post"> | |
2 | 119 <p> |
120 <textarea name="data" cols="100" rows="20"></textarea> | |
0 | 121 <input type="hidden" value="1" name="mode" /> |
2 | 122 </p> |
0 | 123 <div class="icenter"> |
124 <input type="submit" value=" Submit " /> | |
125 </div> | |
126 </form> | |
127 <? | |
128 } | |
2 | 129 |
130 /* | |
131 * Parse and validate item | |
132 */ | |
0 | 133 else if ($formMode == 1) { |
134 if (isset($_POST["data"])) { | |
135 $formData = stripslashes($_POST["data"]); | |
136 | |
137 $postData = explode("\n", $formData); | |
138 $data = array(); | |
139 $ignored = array(); | |
140 | |
2 | 141 function addItems($num, $desc) |
142 { | |
143 global $data; | |
144 for ($i = 0; $i < $num; $i++) | |
145 $data["items"][] = $desc; | |
146 } | |
147 | |
0 | 148 foreach ($postData as $line) { |
149 // Trim whitespace | |
150 $str = trim($line); | |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
151 if ($str == "") continue; |
0 | 152 |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
153 // Strip glows and counters from item "handle" |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
154 if (preg_match("/^(.+?)\s+(<.+? glow>|\(\d+\/\d+\)|\[\d+\/\d+\])$/", $str, $m)) |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
155 $str = $m[1]; |
0 | 156 |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
157 // Discard multi-item lines |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
158 if (preg_match("/^(many|two|three|four|five|six|seven|eight|nine|ten)\s+(.+?)( labeled as .+|)$/", $str, $m)) { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
159 if (!isset($fixNumbers[$m[1]])) { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
160 $ignored[$str] = "Unparsed stack of many"; |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
161 } else { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
162 $n = $fixNumbers[$m[1]]; |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
163 $changed = 0; |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
164 foreach ($fixItemTable as $pat => $rep) { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
165 if ($pat[0] == "*") { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
166 if (substr($pat, 1) == $m[2]) { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
167 $res = $rep; |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
168 $changed = 1; |
2 | 169 } |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
170 } else { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
171 $res = preg_replace("/".$pat."/", $rep, $m[2], -1, &$changed); |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
172 } |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
173 if ($changed > 0) { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
174 addItems($n, $res.$m[3]); |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
175 break; |
2 | 176 } |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
177 } |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
178 if ($changed == 0) { |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
179 $ignored[$str] = "Unsupported item stack"; |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
180 } |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
181 } |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
182 } else |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
183 addItems(1, $str); |
0 | 184 } |
185 | |
186 if (count($ignored) > 0) { | |
187 ?> | |
188 <p>Item data processed. Following lines <b>were not accepted</b>:</p> | |
189 <table> | |
190 <tr><th>Item</th><th>Reason</th></tr> | |
191 <? | |
192 foreach ($ignored as $name => $reason) { | |
193 echo " <tr><td>".htmlentities($name)."</td><td>".htmlentities($reason)."</td></tr>\n"; | |
194 } | |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
195 |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
196 $encData = base64_encode(serialize($data)); |
0 | 197 ?> |
198 </table> | |
199 | |
200 <form action="<? echo $pageIndex; ?>" method="post"> | |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
201 <input type="hidden" value="<? echo $encData ?>" name="data" /> |
0 | 202 <input type="hidden" value="2" name="mode" /> |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
203 <? |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
204 // echo "<textarea name=\"data\" cols=\"100\" rows=\"20\">".$encData."</textarea>\n"; |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
205 ?> |
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
206 <br /> |
0 | 207 <input type="submit" value=" Continue " /> |
208 </form> | |
209 <? | |
210 } else | |
211 $formMode = 3; | |
212 } else { | |
213 $errorMsg = "No item data provided."; | |
214 $errorSet = TRUE; | |
215 } | |
3
aeb37c6b16fd
Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
216 } // formMode == 1 |
0 | 217 |
1 | 218 |
219 /* | |
220 * Unserialize data from previous step | |
221 */ | |
0 | 222 if ($formMode == 2) { |
223 if (isset($_POST["data"])) { | |
224 $formData = base64_decode($_POST["data"]); | |
225 $data = @unserialize($formData); | |
226 $formMode = 3; | |
227 } | |
228 if ($data === FALSE) { | |
229 $errorMsg = "Could not unserialize data, internal error."; | |
230 $errorSet = TRUE; | |
231 } | |
232 } | |
233 | |
1 | 234 |
235 /* | |
236 * Interactive editor mode begins here | |
237 */ | |
2 | 238 if ($data !== FALSE && $formMode == 3) { |
0 | 239 ?> |
240 <form id="done" action="<? echo $pageIndex; ?>" method="post"> | |
1 | 241 <p id="create_buttons"> |
2 | 242 <input type="button" value=" Create BatMUD Commands " onclick="createInit('batmud');" /> |
243 <!-- <input type="button" value=" Create TinyFugue Macros " onclick="createInit('tf');" /> | |
1 | 244 --> |
2 | 245 <input type="button" value=" Create SAVEBLOB " onclick="createInit('save');" /> |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
246 <input type="button" value=" Reset All " onclick="resetAll();" /> |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
247 <input type="button" value=" Clear Containers " onclick="clearContainers();" /> |
0 | 248 </p> |
1 | 249 |
250 | |
0 | 251 <table> |
252 <tr> | |
1 | 253 |
0 | 254 <td> |
255 <h2>Items pool</h2> | |
1 | 256 <? printOptionSelect("curr_items", 10, TRUE); ?> |
257 <table class="buttons"> | |
258 <tr> | |
259 <td><input type="button" value=" Delete " onclick="deleteItems(this.form);" /></td> | |
260 <td><input type="button" value=" Add new " onclick="addItems(this.form);" disabled="disabled" /></td> | |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
261 <td><b><span id="curr_nitems"></span> items</b></td> |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
262 <td><input type="button" value=" AutoMove " onclick="autoMoveItems(this.form);" /></td> |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
263 <td style="width: 60%; text-align: right;"><input type="button" value=" Move to container " onclick="moveItems(this.form);" /></td> |
1 | 264 </tr> |
0 | 265 </table> |
266 </td> | |
1 | 267 |
6 | 268 <td id="container_editor"> |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
269 <h2>Editing container "<span id="curr_name"></span>"</h2> |
6 | 270 <? printOptionSelect("curr_container", 10, TRUE); ?> |
1 | 271 <table class="buttons"> |
272 <tr> | |
6 | 273 <td><input type="button" value=" Remove selected " onclick="containerRemoveItems(this.form);" /></td> |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
274 <td><b><span id="curr_info"></span> items</b></td> |
1 | 275 </tr> |
276 </table> | |
0 | 277 </td> |
278 </tr> | |
1 | 279 |
0 | 280 <tr> |
281 <td> | |
6 | 282 <h2>Create / edit a container</h2> |
0 | 283 <? |
6 | 284 printInputField("container_name", "Identifier/name", 15); |
285 printInputField("container_slots", "Number of slots", 5); | |
0 | 286 ?> |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
287 <input type="button" value=" Create new " onclick="containerCreate(this.form);" id="create_button" /> |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
288 <input type="button" value=" Modify " onclick="containerModify(this.form);" id="modify_button" /> |
0 | 289 </td> |
1 | 290 |
6 | 291 <td id="container_list_editor"> |
292 <h2>Defined containers</h2> | |
293 <? printOptionSelect("container_list", 5, FALSE); ?> | |
1 | 294 <table class="buttons"> |
295 <tr> | |
6 | 296 <td><input type="button" value=" Switch to " onclick="containerEdit(this.form);" /></td> |
297 <td><input type="button" value=" Delete " onclick="containerDelete(this.form);" /></td> | |
1 | 298 </tr> |
299 </table> | |
0 | 300 </td> |
1 | 301 |
0 | 302 </tr> |
303 </table> | |
304 </form> | |
1 | 305 |
2 | 306 <div id="commands"> |
307 <textarea id="command_data" cols="80" rows="10"></textarea> | |
308 <br /> | |
309 <input type="button" value=" Close " onclick="viewCommands(false, '');" /> | |
310 </div> | |
311 | |
312 <div id="options_batmud" class="options"> | |
313 <? printInputField("cmd_delim", "Command delimiter", 15, ";"); ?><br /> | |
314 <? printInputField("cmd_prefix", "Command name prefix", 15, "mcp"); ?><br /> | |
6 | 315 <? printInputField("cmd_cmd", "Command", 32, "put \$1 in \$2"); ?> (<b>$1</b> = item, <b>$2</b> = container)<br /> |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
316 <? printCheckBox("cmd_sequence", "Create sequence for each item, instead of command alias list.", FALSE); ?><br /> |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
317 <? printCheckBox("cmd_autoclose", "Add commands for automatically opening and closing each container.", FALSE); ?><br /> |
6 | 318 <br /> |
2 | 319 <input type="button" value=" Create " onclick="createCommands('batmud');" /> |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
320 <input type="button" value=" Cancel " onclick="createInit('clear');" /> |
2 | 321 </div> |
322 | |
323 <div id="options_tf" class="options"> | |
324 <input type="button" value=" Create " onclick="createCommands('tf');" /> | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
325 <input type="button" value=" Cancel " onclick="createInit('clear');" /> |
2 | 326 </div> |
327 | |
1 | 328 |
329 <div id="status"> </div> | |
330 | |
0 | 331 <script type="text/javascript"> |
332 <!-- | |
6 | 333 var curr_container = null; |
0 | 334 |
6 | 335 function Container(name, slots, items) |
0 | 336 { |
337 this.name = name; | |
338 this.slots = slots; | |
339 this.items = items; | |
340 this.changed = true; | |
341 | |
2 | 342 this.getCountByName = function(n) { |
343 var cnt = 0; | |
344 for (var i = 0; i < this.items.length; i++) { | |
345 if (this.items[i] == n) cnt++; | |
346 } | |
347 return cnt; | |
348 } | |
349 | |
0 | 350 this.getSpace = function() { |
351 return this.slots - this.items.length; | |
352 } | |
353 | |
354 this.addItem = function(item) { | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
355 if (this.items.length < slots) { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
356 this.changed = true; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
357 this.items.push(item); |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
358 return true; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
359 } else |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
360 return false; |
0 | 361 } |
362 | |
363 this.deleteItemById = function(id) { | |
364 this.changed = true; | |
365 delete this.items[id]; | |
366 } | |
367 | |
368 this.flush = function() { | |
369 this.changed = true; | |
370 for (var i = 0; i < this.items.length; i++) { | |
371 if (this.items[i] == undefined) { | |
372 this.items.splice(i, 1); | |
373 i -= 1; | |
374 } | |
375 } | |
376 } | |
377 | |
6 | 378 this.moveItemById = function(container, id) { |
0 | 379 var item = this.getItemByIndex(id); |
380 if (item != null) { | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
381 if (!container.addItem(item)) |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
382 return false; |
0 | 383 this.deleteItemById(id); |
384 this.changed = true; | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
385 return true; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
386 } else |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
387 return false; |
0 | 388 } |
389 | |
390 this.getItemId = function(item) { | |
391 return this.items.indexOf(item); | |
392 } | |
393 | |
394 this.getItemByIndex = function(id) { | |
1 | 395 if (id < 0 || id >= this.items.length) return null; |
0 | 396 return this.items[id]; |
397 } | |
398 } | |
399 --> | |
400 <? | |
6 | 401 function getContainerObject($name, $slots, $items) |
0 | 402 { |
6 | 403 return "new Container(\"".$name."\", \"".$slots."\", [".getJSArraySegment($items)."])"; |
0 | 404 } |
405 | |
406 $str = ""; | |
6 | 407 if (isset($data["containers"])) { |
408 foreach ($data["containers"] as $container) { | |
0 | 409 if ($str != "") $str .= ", "; |
6 | 410 $str .= getContainerObject($container["name"], $container["slots"], $container["items"]); |
0 | 411 } |
412 } | |
413 | |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
414 echo " |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
415 var list_containers; |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
416 var list_items; |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
417 |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
418 function initContainers() |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
419 { |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
420 list_containers = [".$str."]; |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
421 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
422 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
423 function initItems() |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
424 { |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
425 list_items = ".(isset($data["items"]) ? getContainerObject("items", 10000, $data["items"]) : "null")."; |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
426 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
427 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
428 function initSettings() |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
429 { |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
430 ".$jsData." |
10
e2f975b0c518
Fix reset functionality. Add startup message.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
431 curr_container = null; |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
432 } |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
433 "; |
0 | 434 ?> |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
435 <!-- kludge --><!-- |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
436 |
0 | 437 |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
438 function resetAll() |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
439 { |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
440 var answer = confirm("Really delete all defined containers and reset item pool to original state? You will have to re-define containers from scratch."); |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
441 if (!answer) { |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
442 statusMsg("Reset operation cancelled."); |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
443 return; |
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
444 } |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
445 initContainers(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
446 initItems(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
447 initSettings(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
448 updatePage(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
449 statusMsg('Welcome to the editor. <b>(c) Copyright 2011 Matti Hämäläinen aka Ggr Pupunen.</b>'); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
450 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
451 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
452 function clearContainers() |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
453 { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
454 var answer = confirm("Really clear (empty) all defined containers and reset item pool to original state?"); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
455 if (!answer) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
456 statusMsg("Clear operation cancelled."); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
457 return; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
458 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
459 initItems(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
460 for (var i = 0; i < list_containers.length; i++) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
461 list_containers[i].items = []; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
462 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
463 updatePage(); |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
464 } |
0 | 465 |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
466 |
0 | 467 function setHTML(id, str) |
468 { | |
469 var o = document.getElementById(id); | |
470 if (o != null) | |
471 o.innerHTML = str; | |
472 } | |
473 | |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
474 |
0 | 475 function setListData(id, list) |
476 { | |
477 var o = document.getElementById(id); | |
478 o.options.length = 0; | |
479 for (var i = 0; i < list.length; i++) { | |
480 o.options[i] = new Option(list[i], i, false, false); | |
481 } | |
482 } | |
483 | |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
484 |
0 | 485 // Update the form data |
486 function updatePage() | |
487 { | |
488 // List of items | |
2 | 489 if (list_items != null && list_items.changed) { |
490 list_items.changed = false; | |
0 | 491 setListData("curr_items", list_items.items); |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
492 setHTML("curr_nitems", list_items.items.length); |
2 | 493 } |
0 | 494 |
6 | 495 // List of containers |
496 var container_list_editor = document.getElementById("container_list_editor"); | |
497 if (list_containers.length > 0) { | |
498 container_list_editor.style.display = "block"; | |
0 | 499 |
6 | 500 o = document.getElementById("container_list"); |
0 | 501 o.options.length = 0; |
6 | 502 for (var i = 0; i < list_containers.length; i++) { |
503 o.options[i] = new Option(list_containers[i].name +" (" + list_containers[i].items.length +" of "+ list_containers[i].slots +" items)", i, false); | |
0 | 504 } |
505 } else { | |
6 | 506 container_list_editor.style.display = "none"; |
0 | 507 } |
508 | |
509 | |
6 | 510 // Update current container |
511 var container_editor = document.getElementById("container_editor"); | |
512 if (curr_container != null) { | |
513 container_editor.style.display = "block"; | |
514 setHTML("curr_name", curr_container.name); | |
4 | 515 |
12
774db3b4bedc
Add some informational output.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
516 setHTML("curr_info", curr_container.items.length+" / "+curr_container.slots); |
4 | 517 |
6 | 518 if (curr_container.changed) { |
519 curr_container.changed = false; | |
520 setListData("curr_container", curr_container.items); | |
2 | 521 } |
0 | 522 } else { |
6 | 523 container_editor.style.display = "none"; |
0 | 524 } |
525 } | |
526 | |
527 // Output status message | |
528 function statusMsg(msg) | |
529 { | |
530 var o = document.getElementById("status"); | |
531 o.innerHTML = msg; | |
532 } | |
533 | |
534 | |
535 // Clear values of a given form | |
536 function clearForm(f) | |
537 { | |
538 for (var i = 0; i < f.elements.length; i++) { | |
539 var e = f.elements[i]; | |
540 if (e.type.toLowerCase() == "text") e.value = ""; | |
541 } | |
542 } | |
543 | |
544 | |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
545 function validateContainerData(f) |
0 | 546 { |
6 | 547 var name = f.elements['container_name'].value; |
548 var slots = parseInt(f.elements['container_slots'].value, 10); | |
0 | 549 |
1 | 550 if (isNaN(slots) || slots < 1) { |
551 statusMsg("Number of slots not set or is invalid."); | |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
552 return null; |
0 | 553 } |
554 | |
555 if (name == "") { | |
6 | 556 statusMsg("Empty container name "+name+"."); |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
557 return null; |
0 | 558 } |
1 | 559 |
2 | 560 if (name.match(/[^a-z0-9_]/)) { |
6 | 561 statusMsg("Invalid container name, only lower case alphanumerics and underscore are allowed."); |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
562 return null; |
1 | 563 } |
0 | 564 |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
565 return {name: name, slots: slots}; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
566 } |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
567 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
568 // Create a new container, set current container to it |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
569 function containerCreate(f) |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
570 { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
571 var c = validateContainerData(f); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
572 if (c == null) |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
573 return; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
574 |
6 | 575 for (var i = 0; i < list_containers.length; i++) { |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
576 if (list_containers[i].name == c.name) { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
577 statusMsg("Container with identifier '<b>"+c.name+"</b>' already exists!"); |
0 | 578 return; |
579 } | |
580 } | |
581 | |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
582 curr_container = new Container(c.name, c.slots, []); |
6 | 583 list_containers.push(curr_container); |
0 | 584 |
585 clearForm(f); | |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
586 statusMsg("Created new container '<b>"+c.name+"</b>' with <b>"+c.slots+"</b> slots."); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
587 updatePage(); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
588 } |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
589 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
590 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
591 // Change current container |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
592 function containerModify(f) |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
593 { |
10
e2f975b0c518
Fix reset functionality. Add startup message.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
594 if (curr_container == null) { |
e2f975b0c518
Fix reset functionality. Add startup message.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
595 statusMsg("No current container, create or select one."); |
e2f975b0c518
Fix reset functionality. Add startup message.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
596 return; |
e2f975b0c518
Fix reset functionality. Add startup message.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
597 } |
e2f975b0c518
Fix reset functionality. Add startup message.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
598 |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
599 var c = validateContainerData(f); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
600 if (c == null) |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
601 return; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
602 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
603 if (c.slots < curr_container.items.length) { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
604 statusMsg("New number of slots can't be smaller than number of items in it! ("+ c.slots +" < "+ curr_container.items.length +")"); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
605 return; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
606 } |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
607 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
608 curr_container.name = c.name; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
609 curr_container.slots = c.slots; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
610 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
611 clearForm(f); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
612 statusMsg("Updated container."); |
0 | 613 updatePage(); |
614 } | |
615 | |
616 | |
6 | 617 function containerCheckSelected(f) |
1 | 618 { |
6 | 619 var id = f.elements['container_list'].selectedIndex; |
1 | 620 |
6 | 621 if (id < 0 || id >= list_containers.length) { |
622 statusMsg("Invalid container, internal error!"); | |
1 | 623 return -1; |
624 } | |
625 | |
6 | 626 return {id: id, container: list_containers[id]}; |
1 | 627 } |
628 | |
629 | |
6 | 630 // Delete a container from container list |
631 function containerDelete(f) | |
0 | 632 { |
6 | 633 var ret = containerCheckSelected(f); |
634 if (ret.id < 0 || ret.container == null) return; | |
1 | 635 |
6 | 636 var name = ret.container.name; |
637 var len = ret.container.items.length; | |
1 | 638 |
6 | 639 var answer = confirm("Really delete selected container '"+name+"' and move "+len+" items back to pool?"); |
1 | 640 if (!answer) { |
641 statusMsg("Delete operation cancelled."); | |
642 return; | |
643 } | |
644 | |
6 | 645 if (curr_container == ret.container) |
646 curr_container = null; | |
1 | 647 |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
648 for (var i = 0; i < len; i++) { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
649 if (!ret.container.moveItemById(list_items, i)) { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
650 statusMsg("Internal error moving item "+ i); |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
651 return; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
652 } |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
653 } |
1 | 654 |
6 | 655 list_containers.splice(ret.id, 1); |
1 | 656 |
657 if (len > 0) { | |
6 | 658 statusMsg("Deleted container '"+name+"', "+len+" items returned to pool."); |
1 | 659 } else { |
6 | 660 statusMsg("Deleted empty container '"+name+"'."); |
1 | 661 } |
662 updatePage(); | |
663 } | |
664 | |
665 | |
6 | 666 // Change currently edited container to another |
667 function containerEdit(f) | |
1 | 668 { |
6 | 669 var ret = containerCheckSelected(f); |
670 if (ret.id < 0 || ret.container == null) return; | |
1 | 671 |
6 | 672 curr_container = ret.container; |
673 curr_container.changed = true; | |
674 statusMsg("Switched to container '"+ret.container.name+"'."); | |
0 | 675 updatePage(); |
676 } | |
677 | |
678 | |
9
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
679 function containerRemoveItems(f) |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
680 { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
681 if (curr_container == null) { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
682 statusMsg("Internal error."); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
683 return; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
684 } |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
685 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
686 var selected = getSelectedItems(f.elements['curr_container']); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
687 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
688 if (selected.length == 0) { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
689 statusMsg("No items selected for deletion."); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
690 return; |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
691 } else { |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
692 for (var i = 0; i < selected.length; i++) |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
693 curr_container.moveItemById(list_items, selected[i]); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
694 |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
695 curr_container.flush(); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
696 updatePage(); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
697 statusMsg("Removed " + selected.length + " from current container."); |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
698 } |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
699 } |
da404b8ff282
Container editing, persistent settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
700 |
0 | 701 function getSelectedItems(items) |
702 { | |
703 var selected = []; | |
704 if (items != null) { | |
705 for (var i = 0; i < items.length; i++) | |
706 if (items[i].selected) selected.push(items[i].value); | |
707 } | |
708 return selected; | |
709 } | |
710 | |
711 | |
712 function deleteItems(f) | |
713 { | |
714 var selected = getSelectedItems(f.elements['curr_items']); | |
715 | |
716 if (selected.length == 0) { | |
717 statusMsg("No items selected for deletion."); | |
718 return; | |
719 } else { | |
720 var answer = confirm("Really delete selected items?"); | |
721 if (!answer) { | |
722 statusMsg("Delete operation cancelled."); | |
723 return; | |
724 } | |
725 | |
726 for (var i = 0; i < selected.length; i++) | |
727 list_items.deleteItemById(selected[i]); | |
728 | |
729 list_items.flush(); | |
730 updatePage(); | |
731 statusMsg("Deleted "+selected.length+" items."); | |
732 } | |
733 } | |
734 | |
735 | |
736 function moveItems(f) | |
737 { | |
6 | 738 if (curr_container == null) { |
739 statusMsg("No container selected, cannot move items."); | |
0 | 740 return; |
741 } | |
742 | |
743 var selected = getSelectedItems(f.elements['curr_items']); | |
744 | |
745 if (selected.length == 0) { | |
746 statusMsg("No items selected for deletion."); | |
747 return; | |
748 } else { | |
6 | 749 if (curr_container.getSpace() < selected.length) { |
750 statusMsg("Not enough space! "+ selected.length +" items, only "+ curr_container.getSpace() +" slots available!"); | |
0 | 751 return; |
752 } | |
753 | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
754 for (var i = 0; i < selected.length; i++) { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
755 if (!list_items.moveItemById(curr_container, selected[i])) { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
756 statusMsg("Internal error moving item #"+i+": '"+selected[i]+"'."); |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
757 return; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
758 } |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
759 } |
0 | 760 |
761 list_items.flush(); | |
762 updatePage(); | |
6 | 763 statusMsg("Moved " + selected.length + " items to current container."); |
0 | 764 } |
765 } | |
766 | |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
767 function autoMoveItems(f) |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
768 { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
769 var selected = getSelectedItems(f.elements['curr_items']); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
770 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
771 if (selected.length == 0) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
772 statusMsg("No items selected for AutoMove(tm)."); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
773 return; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
774 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
775 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
776 if (list_containers.length == 0) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
777 statusMsg("No containers available for AutoMove(tm)."); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
778 return; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
779 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
780 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
781 var remaining = selected.length; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
782 var n = 0; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
783 while (remaining > 0 && n < list_containers.length) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
784 curr = list_containers[n]; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
785 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
786 for (var q = curr.getSpace(); q > 0 && remaining > 0; q--) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
787 remaining--; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
788 if (!list_items.moveItemById(curr, selected[remaining])) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
789 statusMsg("Internal error moving item #"+remaining+": '"+selected[remaining]+"'."); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
790 return; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
791 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
792 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
793 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
794 n++; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
795 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
796 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
797 list_items.flush(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
798 updatePage(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
799 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
800 if (remaining > 0) { |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
801 statusMsg("Not enough space! <b>"+ remaining +" of "+ selected.length +"</b> items left without slots!"); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
802 return; |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
803 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
804 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
805 statusMsg("AutoMoved " + selected.length + " items to containers."); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
806 } |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
807 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
808 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
809 |
0 | 810 |
2 | 811 var edit_modes = ['batmud', 'tf', 'save']; |
1 | 812 |
2 | 813 function createInit(mode) |
814 { | |
815 for (i = 0; i < edit_modes.length; i++) { | |
816 var o = document.getElementById("options_"+edit_modes[i]); | |
817 if (o != null) { | |
818 o.style.display = (edit_modes[i] == mode) ? "block" : "none"; | |
819 } | |
820 } | |
821 if (mode == "save") | |
822 createCommands(mode); | |
823 } | |
824 | |
825 | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
826 function expandCmd(cmd, item, name) |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
827 { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
828 var str = cmd.replace(/\$1/g, item); |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
829 return str.replace(/\$2/g, name); |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
830 } |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
831 |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
832 |
2 | 833 function createCommands(mode) |
1 | 834 { |
6 | 835 if (list_containers.length == 0) { |
836 statusMsg("No container configurations defined!"); | |
1 | 837 return; |
838 } | |
2 | 839 |
840 | |
1 | 841 var str = ""; |
6 | 842 for (var i = 0; i < list_containers.length; i++) { |
843 var container = list_containers[i]; | |
2 | 844 var counts = []; |
845 var curr = []; | |
846 | |
6 | 847 for (var n = 0; n < container.items.length; n++) { |
848 var cnt = container.getCountByName(container.items[n]); | |
849 counts[container.items[n]] = cnt; | |
850 curr[container.items[n]] = 1; | |
2 | 851 } |
852 | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
853 var cmd_autoclose = document.getElementById("cmd_autoclose").checked; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
854 var cmd_delim = document.getElementById("cmd_delim").value; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
855 var cmd_prefix = document.getElementById("cmd_prefix").value; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
856 if (cmd_delim == "") cmd_delim = ";"; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
857 var cmd_cmd = document.getElementById("cmd_cmd").value; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
858 var cmd_seq = document.getElementById("cmd_sequence").checked; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
859 var s = ""; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
860 |
6 | 861 for (var n = 0; n < container.items.length; n++) { |
862 var item = container.items[n]; | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
863 var tmp = ""+item; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
864 |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
865 if (counts[item] > 1) { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
866 tmp += " " + curr[item]; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
867 curr[item]++; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
868 } |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
869 |
1 | 870 if (mode == "batmud") { |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
871 if (cmd_seq) { |
8
5e1cdf22d647
Cleanups, fixes, added a global "reset" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
872 s += expandCmd(cmd_cmd, tmp, container.name) + "\n"; |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
873 } else { |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
874 if (s != "") s += ","; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
875 s += tmp; |
2 | 876 } |
1 | 877 } |
878 } | |
2 | 879 |
880 if (mode == "batmud") { | |
7
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
881 if (!cmd_seq) str += "command "+cmd_prefix+container.name+" "; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
882 if (cmd_autoclose) str += "open "+container.name+delim; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
883 if (!cmd_seq) str += expandCmd(cmd_cmd, s, container.name); |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
884 else str += s; |
6ff1ee9122b2
Work more on generalization of the process.
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
885 if (cmd_autoclose) str += delim+"close "+container.name; |
2 | 886 str += "\n"; |
887 } | |
1 | 888 } |
889 | |
2 | 890 viewCommands(true, str); |
891 } | |
892 | |
893 function viewCommands(state, str) | |
894 { | |
1 | 895 var o = document.getElementById("commands"); |
2 | 896 o.style.display = state ? "block" : "none"; |
897 var o = document.getElementById("command_data"); | |
1 | 898 o.innerHTML = str; |
899 } | |
900 | |
13
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
901 |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
902 initContainers(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
903 initItems(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
904 initSettings(); |
1edbabcbcdbd
Cleanups, and AutoMove(tm) functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
905 updatePage(); |
0 | 906 --> |
907 </script> | |
908 <? | |
909 } | |
910 | |
911 if ($errorSet) { | |
912 echo "<h2>An error occured</h2>\n". | |
913 "<p>".$errorMsg."</p>"; | |
914 } | |
915 | |
916 printPageFooter(); | |
917 ?> |