Sha256: b77abef869b85033e45574d659a9c34614f4e1ca5db103143aa202d55473d138

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

Tao.Table.Selectable = ->

  @attribute 'selectable', type: 'boolean'

  @get 'selectedRows', ->
    @jq.find('tbody > tr.selected')

  _initSelectable: ->
    @on 'tao:change', '.td-checkbox tao-check-box', (e) =>
      cb = e.currentTarget
      $row = cb.jq.closest('tr')
      @toggleSelectRow $row, cb.checked
      @trigger 'tao:selectedChange', [@selectedRows]

    @on 'tao:change', '.th-checkbox tao-check-box', (e) =>
      cb = e.currentTarget
      if cb.checked
        @selectAllRows()
      else
        @unselectAllRows()
      @trigger 'tao:selectedChange', [@selectedRows]

  toggleSelectRow: (row, selected) ->
    return @ unless @selectable

    $row = $ row
    currentSelected = $row.hasClass('selected')
    selected = !currentSelected if _.isNil selected
    if $row.is('.disabled, .hidden, .expandable-panel')\
        || selected == currentSelected
      return @

    $row.toggleClass 'selected', selected
    cb = $row.find('.td-checkbox tao-check-box').get(0)
    cb.checked = selected if cb.checked != selected
    @

  selectRow: (row) ->
    @toggleSelectRow row, true

  unselectRow: (row) ->
    @toggleSelectRow row, false

  selectAllRows: ->
    return @ unless @selectable
    @jq.find('tbody > tr').each (i, row) => @selectRow(row)
    @

  unselectAllRows: ->
    return @ unless @selectable
    @jq.find('tbody > tr').each (i, row) => @unselectRow(row)
    @

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tao_ui-0.2.9 lib/assets/javascripts/tao/ui/table/selectable.coffee
tao_ui-0.2.8 lib/assets/javascripts/tao/ui/table/selectable.coffee
tao_ui-0.2.7 lib/assets/javascripts/tao/ui/table/selectable.coffee