Skip to content

Instantly share code, notes, and snippets.

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