Sha256: ccc3824d591c472ca713625aab983e3e40e8c69eb8606ad70cb978f09c323180

Contents?: true

Size: 820 Bytes

Versions: 28

Compression:

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

28 entries across 5 versions & 1 rubygems

Version Path
pbw-0.0.8 lib/generators/pbw/area/templates/views/new_view.coffee
pbw-0.0.8 lib/generators/pbw/token/templates/views/new_view.coffee
pbw-0.0.8 lib/generators/pbw/rules/trigger/templates/views/new_view.coffee
pbw-0.0.8 lib/generators/pbw/rules/process/templates/views/new_view.coffee
pbw-0.0.8 lib/generators/pbw/rules/constraint/templates/views/new_view.coffee
pbw-0.0.8 lib/generators/pbw/rules/command/templates/views/new_view.coffee
pbw-0.0.8 lib/generators/pbw/rules/capability/templates/views/new_view.coffee
pbw-0.0.8 lib/generators/pbw/item/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/rules/capability/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/area/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/item/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/rules/command/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/rules/constraint/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/rules/process/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/rules/trigger/templates/views/new_view.coffee
pbw-0.0.7 lib/generators/pbw/token/templates/views/new_view.coffee
pbw-0.0.6 lib/generators/pbw/item/templates/views/new_view.coffee
pbw-0.0.6 lib/generators/pbw/token/templates/views/new_view.coffee
pbw-0.0.6 lib/generators/pbw/rules/command/templates/views/new_view.coffee
pbw-0.0.6 lib/generators/pbw/rules/capability/templates/views/new_view.coffee