Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1820cc228f
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (39 sloc) 1.408 kb
RailsBackboneRelational.Views.Comments ||= {}
class RailsBackboneRelational.Views.Comments.NewView extends Backbone.View
template: JST["backbone/templates/comments/new"]
events:
"submit .field1": "save"
constructor: (options) ->
super(options)
@model = new @collection.model()
@model.bind("change:errors", () =>
this.render()
)
save: (e) ->
e.preventDefault();
#e.keyCode == 13 and
if @$('.content').val() != ''
@model.unset("errors")
@model.set('content', @$('.content').val())
@model.set('title', @$('.title').val())
checked = @$('.direction').is('checked');
@model.set('direction', checked)
@collection.create(@model.toJSON(),
success: (comment) =>
alert('success')
view = new RailsBackboneRelational.Views.Comments.CommentView({model : comment})
tmp = view.render().el
tmp1 = $(@.el).parent().parent().find('.comments-list')
$(tmp1).append(tmp)
@$('.content').val('good')
@$('.title').val('good1')
error: (comment, jqXHR) =>
alert('error')
console.log(comment)
console.log(jqXHR)
@model.set({errors: $.parseJSON(jqXHR.responseText)})
#Backbone.history.navigate('', true);
)
render: ->
$(@el).html(@template(@model.toJSON() ))
return this
Jump to Line
Something went wrong with that request. Please try again.