Merge reward back into habit views & templates

This commit is contained in:
Tyler Renelle 2012-02-11 16:14:48 -05:00
parent 56e14a9161
commit ebbdc6ae1e
5 changed files with 20 additions and 47 deletions

View file

@ -2,14 +2,18 @@
<% if (habit_type==1) { %>
<a href="#" class="vote-up"><img src="assets/add.png" /></a>
<a href="#" class="vote-down"><img src="assets/remove.png" /></a>
<% } else { %>
<!-- Daily & Todos -->
<!-- Rewards -->
<% } else if (habit_type==4) { %>
<a class="buy-link" href=#><img src="assets/dollar.png" /></a>
<!-- Daily & Todos -->
<% } else { %>
<input type="checkbox" <%= done ? "class='vote-down' checked='checked'" : "class='vote-up'" %>/>
<% } %>
<span class="habit-text"><%= name %></span>
<span class="habit-text"><%= name %><%= habit_type==4 ? "($"+score+")" : '' %></span>
<div class='habit-meta'>
<a class="edit-link" href="#/<%= id %>/edit">Edit</a>

View file

@ -1,7 +0,0 @@
<!-- TODO buy link -->
<a class="buy-link" href=#><img src="assets/dollar.png" /></a>
<%= name %>
($<%= score %>)
<div class='edit'>
<a href="#/<%= id %>/edit">Edit</a>
</div>

View file

@ -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")

View file

@ -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() ))

View file

@ -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