Merge reward back into habit views & templates
This commit is contained in:
@@ -17,12 +17,16 @@ class HabitTracker.Views.Habits.HabitView extends Backbone.View
|
||||
@model.vote("up")
|
||||
|
||||
voteDown: =>
|
||||
@model.vote("down")
|
||||
if @model.isReward and (@model.get('score') > window.userStats.get('money'))
|
||||
$('#money').effect("pulsate", 100);
|
||||
else
|
||||
@model.vote("down")
|
||||
|
||||
tagName: "li"
|
||||
|
||||
# why is @model not available in this function? having to pass it in like this
|
||||
dynamicClass: () =>
|
||||
if @model.isReward() then return "reward"
|
||||
output = "habit habit-type-#{@model.get('habit_type')}"
|
||||
if @model.get("done") then output += " done"
|
||||
score = @model.get("score")
|
||||
|
||||
@@ -19,7 +19,13 @@ class HabitTracker.Views.Habits.IndexView extends Backbone.View
|
||||
if (!input.val() or e.keyCode != 13) then return
|
||||
|
||||
# See commit bd7a49c new_view.js.coffee for more code surrounding this functionality
|
||||
@options.habits.create {name: input.val(), habit_type: input.attr('data-type'), position: @options.habits.nextPosition()},
|
||||
new_habit =
|
||||
name: input.val()
|
||||
habit_type: input.attr('data-type')
|
||||
position: @options.habits.nextPosition()
|
||||
# score: ( (input.attr('data-type')=='4') ? 0.0 : 0.0 ) #TODO not working
|
||||
|
||||
@options.habits.create new_habit,
|
||||
#TODO what's this all about?
|
||||
success: (habit) ->
|
||||
@model = habit
|
||||
@@ -51,9 +57,7 @@ class HabitTracker.Views.Habits.IndexView extends Backbone.View
|
||||
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)
|
||||
if habit.isReward()
|
||||
view = new HabitTracker.Views.Habits.RewardView({model : habit})
|
||||
@$("#rewards").append(view.render().el)
|
||||
if habit.isReward() then @$("#rewards").append(view.render().el)
|
||||
|
||||
render: =>
|
||||
$(@el).html(@template(habits: @options.habits.toJSON() ))
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
HabitTracker.Views.Habits ||= {}
|
||||
|
||||
class HabitTracker.Views.Habits.RewardView extends Backbone.View
|
||||
template: JST["backbone/templates/habits/reward"]
|
||||
|
||||
events:
|
||||
"click .destroy" : "destroy"
|
||||
"click .buy-link" : "voteDown"
|
||||
|
||||
destroy: () ->
|
||||
@model.destroy()
|
||||
this.remove()
|
||||
return false
|
||||
|
||||
voteDown: =>
|
||||
if @model.get('score') > window.userStats.get('money')
|
||||
$('#money').effect("pulsate", 100);
|
||||
else
|
||||
@model.vote("down")
|
||||
|
||||
tagName: "li"
|
||||
className: "reward"
|
||||
|
||||
render: ->
|
||||
$(@el).attr('id', "habit_#{@model.get('id')}")
|
||||
$(@el).html(@template(@model.toJSON() ))
|
||||
|
||||
@$(".comment").qtip content:
|
||||
text: (api) ->
|
||||
$(this).next().html()
|
||||
|
||||
return this
|
||||
Reference in New Issue
Block a user