Backbone basically working for habits. still no user data or rewards

This commit is contained in:
Tyler Renelle
2012-02-08 20:40:43 -05:00
parent 34c1d5d46f
commit 58eca5a413
13 changed files with 189 additions and 86 deletions
@@ -13,7 +13,7 @@ class HabitTracker.Views.Habits.EditView extends Backbone.View
@model.save(null,
success : (habit) =>
@model = habit
window.location.hash = "/#{@model.id}"
window.location.hash = "#/index"
)
render : ->
@@ -5,15 +5,31 @@ class HabitTracker.Views.Habits.HabitView extends Backbone.View
events:
"click .destroy" : "destroy"
"click .vote-up" : "voteUp"
"click .vote-down" : "voteDown"
tagName: "tr"
tagName: "li"
destroy: () ->
@model.destroy()
this.remove()
return false
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")
render: ->
$(@el).html(@template(@model.toJSON() ))
@$(".comment").qtip content:
text: (api) ->
$(this).next().html()
return this
@@ -5,16 +5,21 @@ class HabitTracker.Views.Habits.IndexView extends Backbone.View
initialize: () ->
@options.habits.bind('reset', @addAll)
#TODO this is causing "Remaining" tab to be auto-selected
@options.habits.bind('change', @render, this)
addAll: () =>
@options.habits.each(@addOne)
addOne: (habit) =>
view = new HabitTracker.Views.Habits.HabitView({model : habit})
@$("tbody").append(view.render().el)
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)
render: =>
$(@el).html(@template(habits: @options.habits.toJSON() ))
@addAll()
return this
@$("#habits-todos").tabs()
return this
@@ -23,7 +23,7 @@ class HabitTracker.Views.Habits.NewView extends Backbone.View
@collection.create(@model.toJSON(),
success: (habit) =>
@model = habit
window.location.hash = "/#{@model.id}"
window.location.hash = "#/index"
error: (habit, jqXHR) =>
@model.set({errors: $.parseJSON(jqXHR.responseText)})