Sha256: a000ef5976ca815c59960361f0e43917af4f8fbe65e5388b2859a892181fe5e7
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
Luca.fields.CheckboxArray = Luca.core.Field.extend template: "fields/checkbox_array" events: "click input" : "clickHandler" initialize: (@options={})-> _.extend @, @options _.extend @, Luca.modules.Deferrable _.bindAll @, "populateCheckboxes", "clickHandler", "_updateModel" Luca.core.Field::initialize.apply @, arguments @input_id ||= _.uniqueId('field') @input_name ||= @name @label ||= @name @valueField ||= "id" @displayField ||= "name" @selectedItems = [] afterInitialize: (@options={})-> try @configure_collection() catch e console.log "Error Configuring Collection", @, e.message @collection.bind "reset", @populateCheckboxes afterRender: ()-> if @collection?.models?.length > 0 @populateCheckboxes() else @collection.trigger("reset") clickHandler: (event)-> checkbox = event.target if checkbox.checked @selectedItems.push(checkbox.value) else if @selectedItems.indexOf(checkbox.value) isnt -1 @selectedItems = _.without(@selectedItems, [checkbox.value]) @_updateModel() populateCheckboxes: ()-> controls = $(@el).find('.controls') controls.empty() @selectedItems = @getModel().get(@name) @collection.each (model)=> value = model.get(@valueField) label = model.get(@displayField) input_id = _.uniqueId('field') controls.append(Luca.templates["fields/checkbox_array_item"]({label: label, value: value, input_id: input_id, input_name: @input_name})) @$("##{input_id}").attr("checked", "checked") unless @selectedItems.indexOf(value) is -1 $(@container).append(@$el) _updateModel: ()-> attributes = {} attributes[@name] = @selectedItems @getModel().set(attributes) Luca.register "checkbox_array", "Luca.fields.CheckboxArray"
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
luca-0.8.3 | src/components/fields/checkbox_array.coffee |
luca-0.8.2 | src/components/fields/checkbox_array.coffee |