Repository navigation
Expand file tree
/
Copy pathPartyPlanner.js
More file actions
147 lines (118 loc) · 3.2 KB
/
Copy pathPartyPlanner.js
File metadata and controls
147 lines (118 loc) · 3.2 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Items = new Mongo.Collection("items");
MissingItems = new Mongo.Collection("missingItems");
if (Meteor.isClient) {
accountsUIBootstrap3.setLanguage('de');
// This code only runs on the client
Meteor.subscribe("items");
Meteor.subscribe("missingItems");
Template.body.helpers({
items: function () {
// return all items
return Items.find({}, {sort: {createdAt: -1}});
},
missingItems: function () {
// return all items
return MissingItems.find();
}
});
Template.body.events({
"submit .new-item": function (event) {
// This function is called when the new item form is submitted
var text = event.target.text.value;
Meteor.call("addItem", text);
// Clear form
event.target.text.value = "";
// Prevent default form submit
return false;
},
"submit .new-missingItem": function(event){
var text = event.target.text.value;
Meteor.call("addMissingItem", text);
// Clear form
event.target.text.value = "";
// Prevent default form submit
return false;
}
});
Template.item.events({
"click .delete": function () {
Meteor.call("deleteItem", this._id);
},
});
Template.missingItem.events({
"click .delete": function(){
Meteor.call("removeMissingItem", this._id);
}
});
Template.missingItem.helpers({
isAdmin: function(){
return Meteor.user().username === "Sascha";
}
});
Template.registerHelper('equals', function (a, b) {
return a === b;
});
Template.item.helpers({
isOwner: function () {
return this.owner === Meteor.userId();
}
});
Accounts.ui.config({
passwordSignupFields: "USERNAME_ONLY"
});
} else {
Accounts.onCreateUser(function(options, user){
// user registered via Facebook
if(options.profile && user.services && user.services.facebook){
user.username = options.profile.name;
options.profile.picture = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
user.profile = options.profile;
}
return user;
});
}
Meteor.methods({
addItem: function (text) {
// Make sure the user is logged in before inserting a item
if (! Meteor.userId()) {
throw new Meteor.Error("not-authorized");
}
Items.insert({
text: text,
createdAt: new Date(),
owner: Meteor.userId(),
username: Meteor.user().username
});
},
deleteItem: function (itemId) {
var item = Items.findOne(itemId);
if (item.private && item.owner !== Meteor.userId()) {
// If the item is private, make sure only the owner can delete it
throw new Meteor.Error("not-authorized");
}
Items.remove(itemId);
},
addMissingItem: function(text){
// Make sure the user is logged in before inserting a item
if (! Meteor.userId()) {
throw new Meteor.Error("not-authorized");
}
if(!text){
return;
}
MissingItems.insert({
text: text
});
},
removeMissingItem: function(itemId){
MissingItems.remove(itemId);
}
});
if (Meteor.isServer) {
Meteor.publish("items", function () {
return Items.find();
});
Meteor.publish("missingItems", function(){
return MissingItems.find();
});
}