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