Sha256: 4becbbc35ab3d724f2292f7b24870569e3b8576c2202d3d8e4f00364a127c07e

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

<%= view_namespace %> ||= {}

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

  events:
    "submit #edit-<%= singular_name %>": "update"

  constructor: (options) ->
    super(options)
    @model = options.model

    @model.bind("change:errors", () =>
      this.render()
    )

    @model.bind("error", (model, xhr, options) =>
      form_errors 'There was a problem saving <%= singular_name %>', xhr
    )

  update: (e) ->
    e.preventDefault()
    e.stopPropagation()

    @model.save(null,
      success: (<%= singular_name %>, response, options) =>
        @model = <%= singular_name %>
        window.location.hash = "/<%=model_namespace.downcase%>/#{@model.id}"
      error: (model, xhr, options) =>
        form_errors 'There was a problem saving <%= singular_name %>', xhr
    )

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

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

    return this

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pbw-0.0.10 lib/generators/pbw/templates/views/edit_view.coffee