Sha256: a9ee22719ad48f6aefecaf99017694da0e3738a3843c84ea6d4b8644322d6fa6

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

class Lanes.Component.Grid.Editor extends Lanes.Component.Base

    session:
        grid: 'object' # n.b. - not 'state'.  Doing so causes stack overflow since grid also has a 'editor' session var

    events:
        'click .save':   'saveChanges'
        'click .cancel': 'cancelEditing'

    constructor: (config)->
        super
        this.grid = this.parent

    move: (row)->
        if @row
            @grid.fireEvent('cancel-edit',@row)
        @row=row
        @model = this.grid.modelForRow(@row)
        this.render() unless this.rendered
        this.grid.$('.dataTables_scrollBody').append(this.el)
        this.updateFields()

    render: ->
        super
        this.cacheJqElements({
            form: 'form'
        })

    updateFields: ->
        for input, index in this.$('input')
            if definition = this.getColumn(input.name)
                _.dom.setAttribute(input, 'value', this.model.get(definition.field) )
        this.$('input').first().focus()

    persistFields: ->
        for input, index in this.$('input')
            if definition = this.getColumn(input.name)
                @model.set( definition.field, _.dom.getAttribute(input,'value') )

    getColumn: (name)->
        _.findWhere(this.grid.column_definitions, { field: name })

    saveChanges: ->
        this.persistFields()
        @model.save().then => @updateGridRow()

    updateGridRow: ->
        @grid.fireEvent('row-updated', @row)
        @grid.updateRow(@row,@model)
        this.cancelEditing()

    cancelEditing: ->
        @grid.fireEvent('cancel-edit', @row)
        this.detach()
        this.model = null

    deleteCurrent: ->
        @model.destroy().then =>
            @grid.removeRow(@row)
            @cancelEditing()

    fields: ->
        _.map(this.form.children(), (input,index)->
            { index: index, input: Lanes.$(input), column: this.grid.column_definitions[index] }
        ,this)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lanes-0.0.3 client/javascripts/component/grid/Editor.coffee
lanes-0.0.2 client/javascripts/component/grid/Editor.coffee
lanes-0.0.1 client/javascripts/component/grid/Editor.coffee