/
inventory.js
80 lines (70 loc) · 1.83 KB
/
inventory.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var Items = new Meteor.Collection("items");
if (Meteor.isClient) {
Session.set("new", "false");
Session.set("edit", "false");
Meteor.subscribe("items");
Template.items.item = function(){
if(Session.get("search")){
return Items.find({id:{$regex: Session.get("search"), $options: 'i' }}, {sort: {id: 1}});
//{$regex: Session.get("search"), $options: 'i' }
}
else{
return Items.find({},{sort: {id: 1}});
}
}
Template.items.showItems = function(){
return (Session.get("new") === "false");
}
Template.item.events = {
"click #remove": function(){
Items.remove({_id:this._id});
}
}
Template.item.edit = function(){
return (Session.get("edit") === "true");
}
Template.search.events = {
"submit": function(){
Session.set("new", "false");
Session.set("search", $('#search').val());
Session.set("edit", "false");
console.log(Session.get("search"));
$('#search').val("");
},
"click #clear": function(){
Session.set("new", "false");
Session.set("search", "");
Session.set("edit", "false");
console.log("clear");
},
"click #new": function(){
Session.set("new", "true");
Session.set("edit", "false");
console.log("new");
},
"click #edit": function(){
if(Session.get("edit") === "false")
Session.set("edit", "true");
else
Session.set("edit", "false");
console.log("edit");
}
}
Template.insert.showNew = function(){
return (Session.get("new") === "true");
}
Template.insert.events = {
"click #add": function(){
Items.insert({name:$('#name').val(),description:$('#desc').val(),id:$('#id').val()});
Session.set("new", "false");
Session.set("search", $('#id').val());
}
}
}
if (Meteor.isServer) {
Meteor.startup(function () {
Meteor.publish("items", function(){
return Items.find({});
});
});
}