Created
October 20, 2011 02:27
-
-
Save srdjan/1300262 to your computer and use it in GitHub Desktop.
angularjs mvctodo app with coffeescript controller
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