-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbm.js
39 lines (34 loc) · 928 Bytes
/
mbm.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
People = new Meteor.Collection('people');
if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Vote for your fave.";
};
Template.hello.people = function () {
return People.find({}, {sort: {votes: -1}});
};
Template.hello.selectedClass = function () {
var sel = this._id === Session.get('selected');
return sel ? "selected" : ""
};
Template.hello.events({
'click input' : function () {
// template data, if any, is available in 'this'
People.update({_id: Session.get('selected')}, {$inc: {votes: 1}});
},
'click tr': function () {
Session.set('selected', this._id)
}
});
}
if (Meteor.isServer) {
if (People.find().count() === 0) {
var seedData = [
{name: "Sookie", votes: 2},
{name: "Eric", votes: 3},
{name: "Bill", votes: 0}
];
seedData.forEach(function(person) {
People.insert(person);
});
}
}