Created
June 10, 2014 20:02
-
-
Save hellvispresley/0b2e52f10f874c5a1d46 to your computer and use it in GitHub Desktop.
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
<head> | |
<title>Todos</title> | |
</head> | |
<body> | |
<div class="containers"> | |
<div class="login"> | |
{{>loginButtons}} | |
</div> | |
{{>TodosPanel}} | |
</div> | |
</body> | |
<template name="TodosPanel"> | |
<div class="todos-panel"> | |
{{> CreateTodoItem}} | |
<ul class="todos-list"> | |
{{#each items}} | |
<li class="todo-item" {{ isDoneClass}}> | |
{{> TodoItem}} | |
</li> | |
{{/each}} | |
</ul> | |
</div> | |
</template> | |
<template name="TodoItem"> | |
<div class="done"> | |
<input type="checkbox" name="is_done" {{isDoneChecked}} /> | |
</div> | |
<div class="subject"> | |
{{subject}} | |
</div> | |
</template> | |
<template name="CreateTodoItem"> | |
<form class="create-todo"> | |
<input type="text" placeholder="Create new Todo..."/> | |
</form> | |
</template> |
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
Todos = new Meteor.Collection('todos'); | |
if (Meteor.isClient) { | |
Template.TodosPanel.helpers({ | |
items: function() { | |
return Todos.find({},{ | |
sort: { | |
created_at: -1 | |
} | |
}); | |
} | |
}); | |
isDoneClass: function () { | |
return this.is_done ? 'done' : ''; | |
} | |
}); | |
Template.TodoItem.helpers({ | |
isDoneChecked: function() { | |
return this.is_done ? 'checked' : ''; | |
} | |
}); | |
Template.TodoItem.events({ | |
'click [name=is_down]': function (e, tmpl){ | |
var id = this.id; | |
var isDone = tmpl.find('input').checked; | |
Todos.update({_id: id}, { | |
$set: { | |
is_done: isDone | |
} | |
}); | |
} | |
}); | |
Template.CreateTodoItem.events({ | |
'submit form': function(e, tmpl) { | |
e.preventDefault(); | |
var subject = tmpl.find('input').value; | |
Todos.insert({ | |
subject: subject, | |
created_at: new Date, | |
is_done: false | |
}); | |
var form = tmpl.find('form'); | |
form.reset(); | |
} | |
}); | |
} | |
if (Meteor.isServer) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment