Created
November 14, 2014 04:31
-
-
Save shu0115/2cf5b9ed0c9834436aac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tasks = new Mongo.Collection("tasks"); | |
if (Meteor.isClient) { | |
// This code only runs on the client | |
Template.body.helpers({ | |
tasks: function () { | |
if (Session.get("hideCompleted")) { | |
// If hide completed is checked, filter tasks | |
return Tasks.find({checked: {$ne: true}}, {sort: {createdAt: -1}}); | |
} else { | |
// Otherwise, return all of the tasks | |
return Tasks.find({}, {sort: {createdAt: -1}}); | |
} | |
}, | |
hideCompleted: function () { | |
return Session.get("hideCompleted"); | |
}, | |
incompleteCount: function () { | |
return Tasks.find({checked: {$ne: true}}).count(); | |
} | |
}); | |
Template.body.events({ | |
"submit .new-task": function (event) { | |
// This function is called when the new task form is submitted | |
var text = event.target.text.value; | |
Tasks.insert({ | |
text: text, | |
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.text.value = ""; | |
// Prevent default form submit | |
return false; | |
}, | |
"change .hide-completed input": function (event) { | |
Session.set("hideCompleted", event.target.checked); | |
} | |
}); | |
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); | |
} | |
}); | |
Accounts.ui.config({ | |
passwordSignupFields: "USERNAME_ONLY" | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment