habitica/app/assets/javascripts/backbone/routers/habits_router.js.coffee
2012-02-07 19:37:03 -05:00

24 lines
706 B
CoffeeScript

class HabitTracker.Routers.HabitsRouter extends Backbone.Router
initialize: (options) ->
@habits = new HabitTracker.Collections.HabitsCollection()
@habits.reset options.habits
routes:
"/new" : "newHabit"
"/index" : "index"
"/:id/edit" : "edit"
".*" : "index"
newHabit: ->
@view = new HabitTracker.Views.Habits.NewView(collection: @habits)
$("#habits").html(@view.render().el)
index: ->
@view = new HabitTracker.Views.Habits.IndexView(habits: @habits)
$("#habits").html(@view.render().el)
edit: (id) ->
habit = @habits.get(id)
@view = new HabitTracker.Views.Habits.EditView(model: habit)
$("#habits").html(@view.render().el)