habitica/app/assets/javascripts/backbone/views/habits/index_view.js.coffee

32 lines
1.3 KiB
CoffeeScript
Raw Normal View History

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-10 02:14:46 +00:00
@options.habits.bind('change', @render, this) #TODO this ruins tabs, revisit
window.userStats.bind('updatedStats', @updateStats, this)
updateStats: () =>
# TODO create a view & template, bind to existing element
stats = window.userStats
#.to_i.to_s
$('#tnl').html( "(Level #{stats.get('lvl')})   #{Math.round(stats.get('exp'))} / #{stats.tnl()}" )
$( "#progressbar" ).progressbar value: stats.get('exp')/stats.tnl() * 100
2012-02-08 00:09:58 +00:00
addAll: () =>
@options.habits.each(@addOne)
addOne: (habit) =>
view = new HabitTracker.Views.Habits.HabitView({model : habit})
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-10 02:14:46 +00:00
2012-02-08 00:09:58 +00:00
render: =>
$(@el).html(@template(habits: @options.habits.toJSON() ))
@addAll()
@$("#habits-todos").tabs()
return this