-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS
53 lines (45 loc) · 1.31 KB
/
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
Tasks = new Mongo.Collection("tasks");
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
tasks: function () {
// Show newest tasks at the top
return Tasks.find({}, {sort: {name: "asc"}});
}
});
Template.body.events({
"submit .new-task": function (event, template) {
// Prevent default browser form submit
event.preventDefault();
console.log(event.target)
// Get value from form element
var firstName = event.target.firstName.value;
var lastName = event.target.lastName.value;
var rank = event.target.rank.value;
var capid= event.target.capid.value;
var timein = event.target.timein.value;
// Insert a task into the collection
Tasks.insert({
firstName: firstName,
lastName: lastName,
rank: rank,
capid: capid,
timein: timein,
createdAt: new Date() // current time
});
// Clear form
template.find('form').reset();
}
});
Template.task.events({
"click .toggle-checked": function () {
// Set the checked property to the opposite of its current value
Tasks.update(this._id, {
$set: {checked: ! this.checked}
});
},
"click .delete": function () {
Tasks.remove(this._id);
}
});
}