-
Notifications
You must be signed in to change notification settings - Fork 1
/
meteor-class.js
48 lines (41 loc) · 1.06 KB
/
meteor-class.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
Todos = new Meteor.Collection("todos")
if (Meteor.isClient) {
// client code
Template.todo_list.todos = function(){
var filter = Session.get('filter');
if ( !filter ) return Todos.find();
return Todos.find({desc: {$regex: '^.*'+filter+'.*$', $options: 'i'}});
}
Template.todo_list.todosCount = function(){
return Todos.find().fetch().length;
}
Template.todo_list.events = {
'keyup #todo_filter': function(evt){
Session.set('filter', evt.target.value.trim());
}
}
Template.todo_info.events = {
'change input': function(evt){
Todos.update(this._id, {$set: {done: evt.target.checked}});
},
'click span': function(evt){
Todos.remove(this._id);
}
}
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
Todos.allow({
insert: function(userId, item) {
return item.hasOwnProperty('userId');
},
update: function(userId, item) {
return true;
},
remove: function(userId, item) {
return item.userId == userId;
}
});
}