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