Last active
August 29, 2015 14:07
-
-
Save jsonmez/7562e2e0475b4550acd3 to your computer and use it in GitHub Desktop.
Spartan TODO List: JavaScript
This file contains 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
Items = new Meteor.Collection("items"); | |
if (Meteor.isClient) { | |
Template.list.helpers({ | |
items: function() { | |
return Items.find(); | |
}, | |
doneClass: function() { | |
if(this.done) | |
return "done"; | |
else | |
return ""; | |
} | |
}); | |
Template.controls.events({ | |
'submit form': function(event) { | |
event.preventDefault(); | |
var description = $(event.target).find('[id=newItem]').val(); | |
Items.insert({description:description}); | |
} | |
}); | |
Template.list.events({ | |
'click li': function() { | |
Items.update({_id:this._id},{$set:{done:!this.done}}); | |
} | |
}); | |
} | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
if(Items.find().count() == 0) { | |
var items = [ | |
{ description: "Create Meteor app"}, | |
{ description: "Buy an SSD"} | |
]; | |
for(var i =0; i<items.length; i++) { | |
Items.insert(items[i]); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment