Sha256: 6be701f16bb6968d5d80429ec82170c8297e97f4891a4bdd2deaa5d68d0eed13

Contents?: true

Size: 823 Bytes

Versions: 8

Compression:

Stored size: 823 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

8 entries across 8 versions & 1 rubygems

Version Path
rails-backbone-0.8.0 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.7.2 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.7.1 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.7.0 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.6.1 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.6.0 lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.6.0.rc lib/generators/backbone/scaffold/templates/views/new_view.coffee
rails-backbone-0.5.5 lib/generators/backbone/scaffold/templates/views/new_view.coffee