2012-02-08 00:09:58 +00:00
|
|
|
HabitTracker.Views.Habits ||= {}
|
|
|
|
|
|
|
|
|
|
class HabitTracker.Views.Habits.IndexView extends Backbone.View
|
|
|
|
|
template: JST["backbone/templates/habits/index"]
|
|
|
|
|
|
|
|
|
|
initialize: () ->
|
|
|
|
|
@options.habits.bind('reset', @addAll)
|
2012-02-09 01:40:43 +00:00
|
|
|
#TODO this is causing "Remaining" tab to be auto-selected
|
|
|
|
|
@options.habits.bind('change', @render, this)
|
2012-02-08 00:09:58 +00:00
|
|
|
|
|
|
|
|
addAll: () =>
|
|
|
|
|
@options.habits.each(@addOne)
|
|
|
|
|
|
|
|
|
|
addOne: (habit) =>
|
|
|
|
|
view = new HabitTracker.Views.Habits.HabitView({model : habit})
|
2012-02-09 01:40:43 +00:00
|
|
|
if habit.isHabit() then @$("#habits-habits").append(view.render().el)
|
|
|
|
|
if habit.isDaily() then @$("#habits-daily").append(view.render().el)
|
|
|
|
|
if habit.isDoneTodo() then @$("#habits-todos-done").append(view.render().el)
|
|
|
|
|
if habit.isRemainingTodo() then @$("#habits-todos-remaining").append(view.render().el)
|
|
|
|
|
|
2012-02-08 00:09:58 +00:00
|
|
|
render: =>
|
|
|
|
|
$(@el).html(@template(habits: @options.habits.toJSON() ))
|
|
|
|
|
@addAll()
|
2012-02-09 01:40:43 +00:00
|
|
|
@$("#habits-todos").tabs()
|
|
|
|
|
return this
|