-
Notifications
You must be signed in to change notification settings - Fork 2
/
clansio.js
46 lines (42 loc) · 971 Bytes
/
clansio.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
Bulletins = new Meteor.Collection('bulletins');
if (Meteor.isClient) {
Template.bulletins.helpers({
bulletins: function() {
return Bulletins.find({});
},
email: function() {
var user = Meteor.users.findOne({_id: this.userId});
if (user && user.emails) {
return user.emails[0].address;
} else {
return 'Unknown';
}
}
});
Template.addBulletin.events({
'submit form': function(evnt, tmpl) {
evnt.preventDefault();
if(Meteor.userId()) {
var el = $(tmpl.find('input[name="bulletin"]'));
Meteor.call('addBulletin', {
body: el.val()
});
el.val('');
} else {
alert('Please login first');
}
}
});
}
if (Meteor.isServer) {
}
Meteor.methods({
addBulletin: function(data) {
data = data || {};
if (this.userId) {
data.userId = this.userId;
data.when = new Date;
Bulletins.insert(data);
}
}
});