Sha256: e8ba4661e2a8853150e7dd9a29f14b5e296de238da1c52e7fbe097482257af4e
Contents?: true
Size: 1.52 KB
Versions: 7
Compression:
Stored size: 1.52 KB
Contents
class Lanes.Component.ChoicesInput extends Lanes.Component.Base session: selections: 'collection' subViewOptions: -> { field_name: @field_name, mappings: @mappings } constructor: (options={})-> if options.has_many @association = options.model.associations[options.has_many] @field_name = @association.fk else @field_name = options.field_name || options.subViewId @mappings = _.extend({ id: 'id', title: 'title', selected: 'selected' },options.mappings||{}) super initialize: (options={})-> if @association collection = Lanes.Models[@association.model].sharedCollection() collection.fetch().then (m)=> @selections = m this.on('change:model', this.onModelChange ) else if options.data @selections = options.data selectionForID: (id)-> q={}; q[@mappings.id]=id @selections.findWhere( q ) onAttributeChange: (model,fkid)-> this.select( this.selectionForID( fkid ) ) onModelChange: -> if (old_model = this.previousAttributes()['model']) this.stopListening(old_model,"change:#{@association.fk}", this.onAttributeChange ) this.listenTo(@model,"change:#{@association.fk}", this.onAttributeChange ) fk_id = @model.get( @association.fk ) record = if fk_id this.selectionForID( fk_id ) else @model[@association.name] this.select(record)
Version data entries
7 entries across 7 versions & 1 rubygems