Sha256: 40605e1ccce183fd2970fa1c50e88a7fb199732ad15fb615b934605a611611a2

Contents?: true

Size: 1.56 KB

Versions: 19

Compression:

Stored size: 1.56 KB

Contents

Backbone.Poised ||= {}
class Backbone.Poised.LinkedForm extends Backbone.Poised.Form
  tagName: 'form'
  className: 'poised'

  initialize: (options = {}) ->
    throw new Error('Missing `model1` option') unless options.model1?
    throw new Error('Missing `model2` option') unless options.model2?

    # as reference model and for validations
    @model  = options.model1

    @model1 = options.model1
    @model2 = options.model2

    @extractOptions(options)
    @extractFields(options)

  # Bind validations of both models to this view.
  bindValidation: ->
    Backbone.Validation.bind(this, model: @model1)
    Backbone.Validation.bind(this, model: @model2)

  # Instantiates the linked control view for the given field object.
  # Eventually sets the default values for needed options (e.g.
  # models, the parent view, etc.) and sets the correct validation
  # function.
  #
  # @see [Backbone.Poised.Form#controlView]
  #
  # @returns [Backbone.Poised.LinkedControl] view The view for the control
  controlView: (field) ->
    field = _.defaults field,
      model1: @model1
      model2: @model2
      parentView: this
    field.validate = @model1.__proto__.validation and _.has(@model1.__proto__.validation, field.attribute)
    switch field.type
      when 'text' then new Backbone.Poised.LinkedStringControl(field)
      when 'range' then new Backbone.Poised.LinkedRangeControl(field)
      when 'number' then new Backbone.Poised.LinkedNumberControl(field)
      when 'select' then new Backbone.Poised.LinkedSelectControl(field)
      when 'anchor' then new Backbone.Poised.Anchor(field)

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 app/js/vendor/backbone.poised/linked_form.coffee
ela-4.1.5 app/js/vendor/backbone.poised/linked_form.coffee
ela-4.1.4 app/js/vendor/backbone.poised/linked_form.coffee
ela-4.1.3 app/js/vendor/backbone.poised/linked_form.coffee
ela-4.1.2 app/js/vendor/backbone.poised/linked_form.coffee
ela-4.1.1 app/js/vendor/backbone.poised/linked_form.coffee
ela-4.1.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-4.0.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.4.3 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.4.2 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.4.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.3.1 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.3.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.2.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.1.1 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.1.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-3.0.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-2.0.0 app/js/vendor/backbone.poised/linked_form.coffee
ela-1.1.0 app/js/vendor/backbone.poised/linked_form.coffee