Sha256: 827489698e867fa090ab7cc585988fca64b0ced056e7e9c140052e07c0ca45fd

Contents?: true

Size: 821 Bytes

Versions: 7

Compression:

Stored size: 821 Bytes

Contents

<%= view_namespace %> ||= {}

class <%= view_namespace %>.NewView extends Backbone.View
  template: JST["<%= jst 'new' %>"]

  events:
    "submit #new-<%= singular_name %>": "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: (<%= singular_name %>) =>
        @model = <%= singular_name %>
        window.location.hash = "/#{@model.id}"

      error: (<%= singular_name %>, jqXHR) =>
        @model.set({errors: $.parseJSON(jqXHR.responseText)})
    )

  render: ->
    @$el.html(@template(@model.toJSON() ))

    this.$("form").backboneLink(@model)

    return this

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
bbr-wsm-1.1.0 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-1.2.0 lib/generators/backbone/scaffold/templates/views/new_view.coffee
railsy_backbone-0.0.5 lib/generators/backbone/scaffold/templates/views/new_view.coffee
railsy_backbone-0.0.4 lib/generators/backbone/scaffold/templates/views/new_view.coffee
railsy_backbone-0.0.3 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.9.10 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.9.0 lib/generators/backbone/scaffold/templates/views/new_view.coffee