-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveinventory.js
61 lines (48 loc) · 1.39 KB
/
liveinventory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var liveinventory = new function() {
var li = this;
li.filewatcher = undefined;
li.inventoryData = undefined;
li.construct = function() {
li.body = $(document.body)
li.inpFile = li.body.find("input#outputfile");
li.filewatcher = new filewatcher({
onFileSelected: li.onFileSelected,
inputElement: li.inpFile,
onGetContents: li.onGetContents,
onContentsChanged: li.onContentsChanged,
});
}
li.resolveItems = function(items) {
$.ajax({url: "liveinventory-actions.php", type: "post", dataType: "json",
data: JSON.stringify({m:1, items: items}),
success: function(data) {
console.log(data);
}
});
}
// events
li.onFileSelected = function() {
li.filewatcher.getSelectedFileContents();
}
li.onContentsChanged = function(newContents) {
console.log(newContents);
}
li.onGetContents = function(contents) {
var generalSlots = [];
contents = contents.split("\n");
contents = contents.map(function(line) {
var parts = line.split(/\t/);
return {itemName: parts[1], itemID: parts[2], qty: parts[3]}
});
li.resolveItems(contents);
}
// children
this._container = function(opts) {
var c = this;
c.construct = function() {
}
c.construct();
return this;
}
return this;
}