-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.js
92 lines (73 loc) · 2.01 KB
/
simple.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
81
82
83
84
85
86
87
88
89
90
91
92
collections = new Mongo.Collection("collections");
if (Meteor.isClient) {
Meteor.subscribe("collections");
Template.body.helpers({
Tasks: function() {
if(Session.get("hideCompleted")) {
return collections.find({checked : {$ne : true}}, {sort: {createdAt: -1}});
} else {
return collections.find({}, {sort: {createdAt: -1}});
}
},
hideChecked: function() {
return Session.get("hideCompleted");
}
});
Template.body.events({
"submit .new-task": function(event){
var title = event.target.title.value;
if(title != "") {
Meteor.call("addTasks", title);
}
event.target.title.value = "";
return false;
},
"change .partlyCheckbox": function(event) {
Session.set("hideCompleted", event.target.checked);
}
});
Accounts.ui.config({
passwordSignupFields : "USERNAME_ONLY"
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
Meteor.publish("collections", function() {
return collections.find(
{$or: [{private: {$ne: true}}, {owner: this.userId}]},
{sort: {createdAt: -1}}
);
});
}
Meteor.methods({
addTasks: function(title) {
collections.insert({
title: title,
createdAt: new Date(),
owner: Meteor.userId()
});
},
deleteTasks: function(_id) {
var task = collections.findOne(_id);
if(task.owner !== Meteor.userId()) {
throw new Meteor.Error("Not-Authorized");
}
collections.remove(_id);
},
updateTasks: function(_id, checked) {
var task = collections.findOne(_id);
if(task.owner !== Meteor.userId()) {
throw new Meteor.Error("Not-Authorized");
}
collections.update(_id, {$set: {checked : ! checked}});
},
setPrivate: function(_id, private) {
var task = collections.findOne(_id);
if(task.owner !== Meteor.userId()) {
throw new Meteor.Error("Not-Authorized");
}
collections.update(_id, {$set: {private : ! private}});
}
})