Clear completed & add todo at bottom of list

This commit is contained in:
Tyler Renelle
2012-02-11 14:40:32 -05:00
parent b2308aa706
commit 7e674852bb
2 changed files with 26 additions and 23 deletions
@@ -9,7 +9,9 @@ class HabitTracker.Models.Habit extends Backbone.Model
up: true
down: true
done: false
position: 0
# TODO this is being calculated instead on habit creation in index_view
# because HabitsCollection instance isn't available here. Fix that
position: 0
isHabit: =>
@get("habit_type")==1
@@ -50,10 +52,21 @@ class HabitTracker.Models.Habit extends Backbone.Model
done = false if direction=="down"
@set({ score: score, done: done })
window.userStats.updateStats(this, delta)
#send all the update information, as well as tack on userStats which will save to Users
@save({ user_stats: window.userStats })
class HabitTracker.Collections.HabitsCollection extends Backbone.Collection
model: HabitTracker.Models.Habit
url: '/habits'
comparator: (habit) ->
habit.get("position")
# Filter down the list of all todo items that are finished.
doneTodos: ->
@filter (todo) ->
todo.get('done') and todo.isTodo()
nextPosition: ->
if (!@length) then return 1
return @max() + 1