-
Notifications
You must be signed in to change notification settings - Fork 1
/
patient-record.js
58 lines (48 loc) · 1.46 KB
/
patient-record.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
Patients = new Mongo.Collection("patients");
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
patients: function () {
// Show newest patients at the top
return Patients.find({}, {sort: {createdAt: -1}});
}
// patientsCount: function () {
// Show total patients count
// return Patients.find().count()
// }
});
Template.body.events({
"submit .new-patient": function (event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form element
var name = event.target.name.value;
// Add a patient to the MongoDB collection
Patients.insert({
name: name,
createdAt: new Date(), // current time
owner: Meteor.userId(), // _id of logged in user
username: Meteor.user().username // username of logged in user
});
// Clear form
event.target.name.value = "";
}
});
Template.patient.events({
"click .toggle-checked": function () {
// Set the checked property to the opposite of its current value
Patients.update(this._id, {
$set: {checked: ! this.checked}
});
},
"click .delete": function () {
Patients.remove(this._id);
}
});
Accounts.ui.config({
passwordSignupFields: "USERNAME_ONLY"
});
Template.registerHelper("prettifyDate", function (event) {
return new Date().toString('yyyy-MM-dd')
});
}