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