Skip to content

Instantly share code, notes, and snippets.

@steeleforge
Created May 26, 2011 19:51
Show Gist options
  • Save steeleforge/993924 to your computer and use it in GitHub Desktop.
Save steeleforge/993924 to your computer and use it in GitHub Desktop.
SC 2.0a To-Do's coffee-script
Todos = SC.Application.create()
Todos.Todo = SC.Object.extend
title: null
isDone: false
Todos.todosController = SC.ArrayProxy.create
content: []
createTodo: (title) ->
todo = Todos.Todo.create { title: title }
@pushObject(todo)
clearCompletedTodos: ->
@filterProperty('isDone', true).forEach(this.removeObject, this)
remaining: (->
count = @filterProperty('isDone', false).get('length')
).property('@each.isDone')
allAreDone: ((key, value) ->
if value?
@setEach('isDone', value)
value
else
!!@get('length') && @everyProperty('isDone', true)
).property('@each.isDone')
Todos.StatsView = SC.View.extend
remainingBinding: 'Todos.todosController.remaining'
remainingString: (->
remaining = @get('remaining')
if remaining == 1
"#{remaining} item"
else
"#{remaining} items"
).property('remaining')
Todos.CreateTodoView = SC.TextField.extend
insertNewline: ->
value = @get('value')
if value?
Todos.todosController.createTodo(value)
@set('value', '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment