Files
habitica/app/assets/javascripts/backbone/views/habits/edit_view.js.coffee
T
2012-02-15 11:45:42 -05:00

34 lines
725 B
CoffeeScript

HabitTracker.Views.Habits ||= {}
class HabitTracker.Views.Habits.EditView extends Backbone.View
template : JST["backbone/templates/habits/edit"]
events :
"submit #edit-habit" : "update"
"click .destroy" : "destroy"
update : (e) ->
e.preventDefault()
e.stopPropagation()
@model.save(null,
success : (habit) =>
@model = habit
window.location.hash = "#"
)
destroy: () ->
answer = confirm("Are you sure you want to delete this task?")
if (answer)
@model.destroy()
this.remove()
window.location.hash = "#"
return false
render : ->
$(@el).html(@template(@model.toJSON() ))
this.$("form").backboneLink(@model)
return this