-
-
Save jashkenas/994057 to your computer and use it in GitHub Desktop.
SC 2.0a To-Do's coffee-script
This file contains hidden or 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 = SC.Application.create() | |
Todos.Todo = SC.Object.extend | |
title: null | |
isDone: false | |
Todos.todosController = SC.ArrayProxy.create | |
content: [] | |
createTodo: (title) -> | |
@pushObject Todos.Todo.create title: title | |
clearCompletedTodos: -> | |
@filterProperty('isDone', true).forEach @removeObject, this | |
remaining: (-> | |
@filterProperty('isDone', false).get 'length' | |
).property '@each.isDone' | |
allAreDone: ((key, value) -> | |
if value? | |
@setEach 'isDone', value | |
value | |
else | |
!!@get('length') and @everyProperty 'isDone', true | |
).property '@each.isDone' | |
Todos.StatsView = SC.View.extend | |
remainingBinding: 'Todos.todosController.remaining' | |
remainingString: (-> | |
"#{remaining} item" + if @get('remaining') is 1 then '' else 's' | |
).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