corrade-nucleus-nucleons – Blame information for rev 15
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
10 | office | 1 | <!DOCTYPE html> |
2 | |||
3 | <html lang="en"> |
||
4 | <head> |
||
5 | <meta charset="utf-8"> |
||
6 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||
7 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
||
8 | <meta name="description" content="Corrade Nucleon"> |
||
9 | <meta name="author" content="Wizardry and Steamworks"> |
||
10 | <link rel="icon" href="favicon.ico"> |
||
11 | |||
12 | <title>Corrade Nucleus - Pack Rat Inventory Manager</title> |
||
13 | |||
14 | <!-- Bootstrap core CSS --> |
||
15 | <link href="/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"> |
||
16 | <!-- Corrade Nucleus Fonts --> |
||
17 | <link href="/css/nucleus/fonts.css" rel="stylesheet" type="text/css"> |
||
18 | <!-- Customized bootstrap style. --> |
||
19 | <link href="/css/nucleus/nucleus.css" rel="stylesheet" type="text/css"> |
||
20 | |||
21 | <!-- jsTree style --> |
||
22 | <link href="/pack-rat/bower_components/jstree/dist/themes/default/style.min.css" rel="stylesheet" type="text/css"> |
||
23 | </script> |
||
24 | </head> |
||
25 | |||
26 | <body> |
||
27 | <!-- Bootstrap Modal --> |
||
28 | <div id="popup" class="modal fade bs-example-modal-lg" role="dialog"> |
||
29 | <div class="modal-dialog modal-lg"> |
||
30 | <!-- Modal content--> |
||
31 | |||
32 | <div class="modal-content"> |
||
33 | <div class="modal-header"> |
||
34 | <button type="button" class="close" data-dismiss="modal">×</button> |
||
35 | |||
36 | <h1 id="title" class="modal-title"></h1> |
||
37 | </div> |
||
38 | |||
39 | <div id="content" class="modal-body"> |
||
40 | <div class="progress"> |
||
41 | <div id="progressbar" class="progress-bar" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width: 2%;"> |
||
42 | 0% |
||
43 | </div> |
||
44 | </div> |
||
45 | |||
46 | <div class="modal-footer"> |
||
47 | <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> |
||
48 | </div> |
||
49 | </div> |
||
50 | </div> |
||
51 | </div> |
||
52 | </div> |
||
53 | |||
54 | <div class="container"> |
||
55 | <div class="jumbotron"> |
||
56 | <h1>Corrade Pack Rat</h1> |
||
57 | <p class="lead">Pack Rat is an inventory manager for Corrade Nucleus that allows you to sort your inventory and perform other management operations.</p> |
||
58 | <img src="/pack-rat/img/pack-rat.png"></div> |
||
59 | |||
60 | <!-- Will hold the inventory tree (completed dynamically). --> |
||
61 | <div id="tree"> |
||
62 | </div> |
||
63 | |||
64 | <footer class="footer"> |
||
65 | <p>© 2017 Wizardry and Steamworks</p> |
||
66 | </footer> |
||
67 | </div> |
||
68 | <!-- jQuery --> |
||
69 | <script src="/bower_components/jquery/dist/jquery.min.js" type="text/javascript"></script> |
||
70 | <!-- Wizardry and Steamworks JavaScript Includes --> |
||
71 | <script src="/bower_components/was/dist/was.min.js" type="text/javascript"></script> |
||
72 | <!-- Bootstrap Javascript --> |
||
73 | <script type="text/javascript" src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script> |
||
74 | <!-- Bootstrap Form Validator --> |
||
75 | <script src="/pack-rat/bower_components/bootstrap-validator/dist/validator.min.js" type="text/javascript"></script> |
||
76 | <!-- XML <-> JSON --> |
||
77 | <!-- <script src="/bootstrap/bower_components/x2js/xml2json.min.js" type="text/javascript"></script> --> |
||
78 | <!-- CryptoJS --> |
||
79 | <script src="/bower_components/cryptojslib/components/core.js" type="text/javascript"></script> |
||
80 | <script src="/bower_components/cryptojslib/rollups/md5.js" type="text/javascript"></script> |
||
81 | <!-- Form To Object --> |
||
82 | <!-- <script src="/bootstrap/node_modules/form_to_object/dist/formToObject.min.js" type="text/javascript"></script> --> |
||
83 | <!-- Load form processor. --> |
||
84 | <!-- <script src="/bootstrap/js/corrade-bootstrap-processor.js" type="text/javascript"></script> --> |
||
85 | <!-- Moment JS --> |
||
86 | <script src="/pack-rat/bower_components/moment/min/moment.min.js" type="text/javascript"></script> |
||
87 | <!-- JsTree --> |
||
88 | <script src="/pack-rat/bower_components/jstree/dist/jstree.min.js" type="text/javascript"></script> |
||
89 | <!-- JSON to Table --> |
||
90 | <script src="/pack-rat/bower_components/json-to-table/json-to-table.js" type="text/javascript"></script> |
||
91 | <!-- Main script --> |
||
92 | <script type="text/javascript"> |
||
93 | $(function() { |
||
94 | function customMenu(node) { |
||
95 | // The default set of menu items for all types |
||
96 | var items = { |
||
97 | // Grab information about the item. |
||
98 | infoItem: { |
||
99 | label: "Get Info", |
||
100 | action: function(obj) { |
||
101 | $('#popup').dialog({ |
||
102 | width: 800, |
||
103 | height: 600, |
||
104 | modal: true, |
||
105 | resizable: false, |
||
106 | dialogClass: 'no-close texture-dialog' |
||
107 | }).on('dialogclose', function(event) { |
||
108 | $('#content').html(''); |
||
109 | }); |
||
110 | $.ajax({ |
||
111 | type: 'POST', |
||
112 | url: '/', |
||
113 | dataType: 'json', |
||
114 | data: { |
||
115 | command: 'getinventorydata', |
||
116 | item: node.id.split(/[\/]+/).pop(), |
||
117 | data: [ |
||
118 | 'AssetUUID', |
||
119 | 'CreationDate', |
||
120 | 'Description', |
||
121 | 'Permissions', |
||
122 | 'UUID' // part of InventoryBase |
||
123 | ] |
||
124 | } |
||
125 | }).done(function(data) { |
||
126 | $('#content').html(ConvertJsonToTable(data, null, null, null)); |
||
127 | }); |
||
128 | } |
||
129 | } |
||
130 | }; |
||
131 | |||
132 | // Give inventory items menu for anything but folders. |
||
133 | // They could be supported too but would require first |
||
134 | // counting the number of items inside the folder and |
||
135 | // only accepting to send if the number is below max. |
||
136 | if (node.data.type != "folder") { |
||
137 | $.extend(items, { |
||
138 | giveItem: { |
||
139 | label: "Give", |
||
140 | action: function(obj) { |
||
141 | $("#content").html('<form><fieldset class="ui-helper-reset"><label for="firstname">Firstname</label><input type="text" name="firstname" id="firstname" value="" class="ui-widget-content ui-corner-all"><br/><label for="lastname">Lastname</label><input type="text" name="lastname" id="lastname" value="" class="ui-widget-content ui-corner-all"></fieldset></form>'); |
||
142 | $("#popup").dialog({ |
||
143 | width: 320, |
||
144 | height: 180, |
||
145 | modal: true, |
||
146 | resizable: false, |
||
147 | buttons: { |
||
148 | Select: function() { |
||
149 | if ($.trim($("#firstname").val()) == '' || |
||
150 | $.trim($("#lastname").val()) == '') |
||
151 | return; |
||
152 | var firstName = $("#firstname").val(); |
||
153 | var lastName = $("#lastname").val(); |
||
154 | $.ajax({ |
||
155 | type: 'POST', |
||
156 | url: "giveInventoryItem.php?t=" + Math.random(), |
||
157 | data: { |
||
158 | uuid: node.id.split(/[\/]+/).pop(), |
||
159 | firstname: firstName, |
||
160 | lastname: lastName |
||
161 | } |
||
162 | }).done(function(data) { |
||
163 | $("#popup").dialog("close"); |
||
164 | if ($.trim(data) != '') |
||
165 | alert(data); |
||
166 | }); |
||
167 | }, |
||
168 | Cancel: function() { |
||
169 | $("#popup").dialog("close"); |
||
170 | } |
||
171 | } |
||
172 | }).on('dialogclose', function(event) { |
||
173 | $('#content').html(''); |
||
174 | $('#popup').dialog('option', 'buttons', {}); |
||
175 | }); |
||
176 | } |
||
177 | } |
||
178 | }); |
||
179 | } |
||
180 | |||
181 | // The "download" menu item for textures. |
||
182 | if (node.data.type == "texture" || node.data.type == "snapshot") { |
||
183 | $.extend(items, { |
||
184 | downloadItem: { |
||
185 | label: "Download", |
||
186 | "action": function(obj) { |
||
187 | $('#texture').attr('src', 'images/loader.gif'); |
||
188 | $('#popup').dialog({ |
||
189 | width: 800, |
||
190 | height: 600, |
||
191 | modal: true, |
||
192 | resizable: false, |
||
193 | dialogClass: 'no-close texture-dialog' |
||
194 | }).on('dialogclose', function(event) { |
||
195 | $('#content').html(''); |
||
196 | }); |
||
197 | $.ajax({ |
||
198 | type: 'POST', |
||
199 | url: "downloadTexture.php?t=" + Math.random(), |
||
200 | data: { |
||
201 | uuid: node.id.split(/[\/]+/).pop() |
||
202 | } |
||
203 | }).done(function(data) { |
||
204 | $('#content').html('<img src="" align="middle" id="texture">'); |
||
205 | $('#texture').attr('src', "data:image/png;base64," + data); |
||
206 | }); |
||
207 | } |
||
208 | } |
||
209 | }); |
||
210 | } |
||
211 | |||
212 | // The "download" menu item for notecards. |
||
213 | if (node.data.type == "notecard") { |
||
214 | $.extend(items, { |
||
215 | downloadItem: { |
||
216 | label: "Download", |
||
217 | "action": function(obj) { |
||
218 | $('#texture').attr('src', 'images/loader.gif'); |
||
219 | $('#popup').dialog({ |
||
220 | width: 800, |
||
221 | height: 600, |
||
222 | modal: true, |
||
223 | resizable: false, |
||
224 | dialogClass: 'no-close texture-dialog' |
||
225 | }).on('dialogclose', function(event) { |
||
226 | $('#content').html(''); |
||
227 | }); |
||
228 | $.ajax({ |
||
229 | type: 'POST', |
||
230 | url: "downloadNotecard.php?t=" + Math.random(), |
||
231 | data: { |
||
232 | uuid: node.id.split(/[\/]+/).pop() |
||
233 | } |
||
234 | }).done(function(data) { |
||
235 | $.base64.utf8decode = true; |
||
236 | $('#content').html('<pre>' + $.base64.atob(data) + '</pre>'); |
||
237 | }); |
||
238 | } |
||
239 | } |
||
240 | }); |
||
241 | } |
||
242 | |||
243 | // The "download" menu item for sounds. |
||
244 | if (node.data.type == "sound") { |
||
245 | $.extend(items, { |
||
246 | downloadItem: { |
||
247 | label: "Download", |
||
248 | "action": function(obj) { |
||
249 | $('#texture').attr('src', 'images/loader.gif'); |
||
250 | $('#popup').dialog({ |
||
251 | width: 800, |
||
252 | height: 600, |
||
253 | modal: true, |
||
254 | resizable: false, |
||
255 | dialogClass: 'no-close texture-dialog' |
||
256 | }).on('dialogclose', function(event) { |
||
257 | $('#content').html(''); |
||
258 | }); |
||
259 | $.ajax({ |
||
260 | type: 'POST', |
||
261 | url: "downloadSound.php?t=" + Math.random(), |
||
262 | data: { |
||
263 | uuid: node.id.split(/[\/]+/).pop() |
||
264 | } |
||
265 | }).done(function(data) { |
||
266 | $('#content').html('<audio controls="controls"><source id="source" src="" type="audio/mp3"></source></audio>'); |
||
267 | $('#source').attr('src', "data:audio/mp3;base64," + data); |
||
268 | }); |
||
269 | } |
||
270 | } |
||
271 | }); |
||
272 | } |
||
273 | |||
274 | return items; |
||
275 | } |
||
276 | |||
277 | $("#tree").jstree({ |
||
278 | // - sort will sort items by date |
||
279 | // - state will store the open / closed state of the jstree |
||
280 | 'plugins': ["themes", "json_data", "ui", "contextmenu", "sort", "dnd", "state"], |
||
15 | office | 281 | 'contextmenu': { |
10 | office | 282 | "items": function(node) { |
283 | return customMenu(node); |
||
284 | } |
||
15 | office | 285 | }, |
10 | office | 286 | 'dnd': { |
287 | // Do not copy items. |
||
288 | 'copy': false, |
||
289 | // Do not execute the check callback whilst dragging. |
||
290 | 'check_while_dragging': false |
||
291 | }, |
||
292 | 'sort': function(a, b) { |
||
293 | return Date.parse(this.get_node(a).data.time) < |
||
294 | Date.parse(this.get_node(b).data.time) ? 1 : -1; |
||
295 | }, |
||
296 | 'core': { |
||
15 | office | 297 | 'check_callback': function(operation, node, parent, position, more) { |
10 | office | 298 | // Do not allow moves above the root node. |
15 | office | 299 | if (parent.id === "#") |
10 | office | 300 | return false; |
15 | office | 301 | |
302 | var source = node.id; |
||
303 | var target = parent.id; |
||
304 | |||
305 | // Normalize source and target. |
||
306 | if(source === '#') |
||
307 | source = '/'; |
||
308 | |||
309 | if(target === '#') |
||
310 | target = '/'; |
||
311 | |||
312 | if(source == '/' && target == '/') |
||
313 | return; |
||
314 | |||
315 | // Check if source path is sane. |
||
316 | if(source.split('/').some( |
||
317 | function(part) { |
||
318 | return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/.test(part); |
||
319 | })) { |
||
320 | return; |
||
321 | } |
||
322 | |||
323 | // Check if target path is sane. |
||
324 | if(target.split('/').some( |
||
325 | function(part) { |
||
326 | return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/.test(part); |
||
327 | })) { |
||
328 | return; |
||
329 | } |
||
330 | |||
331 | // Check that the source and target items are not system folders. |
||
332 | var data = {}; |
||
333 | [ { type: 'source', value: source }, |
||
334 | { type: 'target', value: target }].forEach(function(e) { |
||
335 | $.ajax({ |
||
336 | //async: false, |
||
337 | type: 'POST', |
||
338 | url: '/', |
||
339 | dataType: 'json', |
||
340 | async: false, |
||
341 | data: { |
||
342 | command: 'getinventorydata', |
||
343 | item: e.value, |
||
344 | data: wasArrayToCSV([ |
||
345 | 'InventoryType', |
||
346 | 'PreferredType' |
||
347 | ]) |
||
348 | } |
||
349 | }).done(function(response) { |
||
350 | if(response.success !== 'True') { |
||
351 | return; |
||
352 | } |
||
353 | data[e.type] = wasKeyValueObjectify( |
||
354 | wasCSVToArray( |
||
355 | response.data |
||
356 | ) |
||
357 | ); |
||
358 | }); |
||
359 | }); |
||
360 | |||
361 | // Do not move the item if: |
||
362 | // ... the retrieved data is empty. |
||
363 | if($.isEmptyObject(data) || |
||
364 | // ... we are trying to move a system folder. |
||
365 | ('PreferredType' in data['source'] && data['source'].PreferredType !== 'Unknown') || |
||
366 | // ... we are trying to move an inventory item over an inventory item. |
||
367 | ('InventoryType' in data['source'] && 'InventoryType' in data['target'])) |
||
368 | return false; |
||
369 | |||
370 | // Move the inventory item. |
||
10 | office | 371 | var moved = false; |
372 | $.ajax({ |
||
15 | office | 373 | //async: false, |
374 | type: 'POST', |
||
375 | url: '/', |
||
376 | dataType: 'json', |
||
377 | async: false, |
||
378 | data: { |
||
379 | command: 'inventory', |
||
380 | action: 'mv', |
||
381 | source: source, |
||
382 | target: target |
||
383 | } |
||
384 | }).done(function(response) { |
||
385 | if(response.success !== 'True') { |
||
10 | office | 386 | return; |
387 | } |
||
388 | moved = true; |
||
389 | }); |
||
15 | office | 390 | |
10 | office | 391 | return moved; |
15 | office | 392 | }, |
10 | office | 393 | data: function(node, callback) { |
394 | if(node.id === '#') { |
||
395 | callback.call(this, [ |
||
396 | { |
||
397 | "id" : "/My Inventory", |
||
398 | "parent" : "#", |
||
399 | "text" : "My Inventory", |
||
400 | "data" : { |
||
401 | "type" : |
||
402 | "folder" |
||
403 | }, |
||
404 | "children" : true, |
||
405 | "opened" : false |
||
406 | }, |
||
407 | { |
||
408 | "id" : "/Library", |
||
409 | "parent" : "#", |
||
410 | "text" : "Library", |
||
411 | "data" : { |
||
412 | "type" : |
||
413 | "folder" |
||
414 | }, |
||
415 | "children" : true, |
||
416 | "opened" : false |
||
417 | } |
||
418 | ]); |
||
419 | return; |
||
420 | } |
||
421 | $.ajax({ |
||
422 | //async: false, |
||
423 | type: 'POST', |
||
424 | url: '/', |
||
425 | dataType: 'json', |
||
426 | data: { |
||
427 | command: 'inventory', |
||
428 | action: 'ls', |
||
429 | path: node.id |
||
430 | } |
||
431 | }).done(function(response) { |
||
14 | office | 432 | var list = []; |
433 | $.each(wasCSVToArray(response.data) |
||
434 | .chunk(10), function(i, e) { |
||
435 | e = wasKeyValueObjectify(e); |
||
436 | list.push({ |
||
437 | 'id' : node.id === '/' ? '/' + e['item'] : node.id + '/' + e['item'], |
||
438 | 'parent' : node.id, |
||
439 | 'data' : { |
||
440 | 'type' : e['type'], |
||
441 | 'time' : e['time'] |
||
442 | }, |
||
443 | 'text' : e['name'], |
||
444 | 'children' : e['type'] === 'folder', |
||
445 | 'icon' : '/pack-rat/img/icons/' + e['type'] + '.png', |
||
446 | 'opened' : 'false' |
||
447 | }); |
||
13 | office | 448 | }); |
14 | office | 449 | callback.call(this, list); |
10 | office | 450 | }); |
451 | } |
||
452 | } |
||
453 | }).bind('move_node.jstree', function(e, data) { |
||
454 | // Once the node is moved, update the node ID to reflect the path change. |
||
455 | var parentPath = data.parent != '/' ? data.parent : ""; |
||
456 | var item = data.node.id.split(/[\/]+/).pop(); |
||
457 | data.instance.set_id(data.node, parentPath + '/' + item); |
||
458 | }); |
||
459 | }); |
||
460 | </script> |
||
461 | </body> |
||
462 | </html> |