Remove new_view & new.jst (since creating inline)
This commit is contained in:
@@ -17,6 +17,8 @@ class HabitTracker.Views.Habits.IndexView extends Backbone.View
|
||||
createOnEnter: (e) ->
|
||||
input = $(e.target)
|
||||
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()},
|
||||
#TODO what's this all about?
|
||||
success: (habit) ->
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
HabitTracker.Views.Habits ||= {}
|
||||
|
||||
class HabitTracker.Views.Habits.NewView extends Backbone.View
|
||||
template: JST["backbone/templates/habits/new"]
|
||||
|
||||
events:
|
||||
"submit #new-habit": "save"
|
||||
|
||||
constructor: (options) ->
|
||||
super(options)
|
||||
@model = new @collection.model()
|
||||
|
||||
@model.bind("change:errors", () =>
|
||||
this.render()
|
||||
)
|
||||
|
||||
save: (e) ->
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
@model.unset("errors")
|
||||
|
||||
@collection.create(@model.toJSON(),
|
||||
success: (habit) =>
|
||||
@model = habit
|
||||
window.location.hash = "#/index"
|
||||
|
||||
error: (habit, jqXHR) =>
|
||||
@model.set({errors: $.parseJSON(jqXHR.responseText)})
|
||||
)
|
||||
|
||||
render: ->
|
||||
$(@el).html(@template(@model.toJSON() ))
|
||||
|
||||
this.$("form").backboneLink(@model)
|
||||
|
||||
return this
|
||||
Reference in New Issue
Block a user