Created
December 4, 2012 12:16
-
-
Save telekosmos/4203206 to your computer and use it in GitHub Desktop.
angularjs mvctodo controller with coffeescript
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
@TodoController = () -> | |
@todos = [] | |
@newTodo = "" | |
@addTodo = () -> | |
if @newTodo.length > 0 | |
@todos.push( { content: @newTodo, done: false, editing: false } ) | |
@newTodo = "" | |
@editTodo = (todo) -> | |
item.editing = false for item in @todos | |
todo.editing = true | |
@finishEditing = (todo) -> todo.editing = false | |
@removeTodo = (todo) -> @todos.remove(todo) | |
countTodos = (list, status) -> | |
(todo for todo in list when todo.done is status).length | |
@remainingTodos = () -> countTodos(@todos, false) | |
@finishedTodos = () -> countTodos(@todos, true) | |
@clearCompletedItems = () -> | |
oldTodos = @todos | |
@todos = [] | |
@todos.push(todo) for todo in oldTodos when not todo.done | |
@hasFinishedTodos = () -> @finishedTodos() > 0 | |
@hasTodos = () -> @todos.length > 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment