Got dynamic class/id working for habits

This commit is contained in:
Tyler Renelle
2012-02-08 21:36:57 -05:00
parent 58eca5a413
commit 9241568472
2 changed files with 40 additions and 29 deletions
@@ -8,8 +8,6 @@ class HabitTracker.Views.Habits.HabitView extends Backbone.View
"click .vote-up" : "voteUp"
"click .vote-down" : "voteDown"
tagName: "li"
destroy: () ->
@model.destroy()
this.remove()
@@ -18,14 +16,30 @@ class HabitTracker.Views.Habits.HabitView extends Backbone.View
voteUp: ->
@model.vote("up")
@trigger("reset")
# console.log($(@el).parent().sibling('#habits-todos-done'))
# if @model.isRemainingTodo and $(@el).parent().id=="habits-remaining-todos"
# $(@el).parent().sibling('#habits-done-todos').append(this)
voteDown: ->
@model.vote("down")
tagName: "li"
# why is @model not available in this function? having to pass it in like this
dynamicClass= (model) ->
output = "habit habit-type-#{model.get('habit_type')}"
if model.get("done") then output += " done"
score = model.get("score")
switch
when score<-8 then output += ' color-red'
when score>=-8 and score<-5 then output += ' color-pink'
when score>=-5 and score<-1 then output += ' color-orange'
when score>=-1 and score<1 then output += ' color-yellow'
when score>=1 and score<5 then output += ' color-green'
when score>=5 and score<10 then output += ' color-light-blue'
when score>=10 then output += ' color-blue'
return output
render: ->
$(@el).attr('id', "habit_#{@model.get('id')}")
$(@el).attr('class', dynamicClass(@model))
$(@el).html(@template(@model.toJSON() ))
@$(".comment").qtip content: