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