Sha256: f46c7c0bfa1cc8b20ba0f887d61576f66110a8e1453493be05117f8b18101997

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

window.ActiveAdmin.CheckboxToggler = class ActiveAdmin.CheckboxToggler
  constructor: (@options, @container)->
    defaults = {}
    @options = $.extend {}, defaults, options
    @_init()
    @_bind()

  _init: ->
    if not @container
      throw new Error('Container element not found')
    else
      @$container = $(@container)

    if not @$container.find('.toggle_all').length
      throw new Error('"toggle all" checkbox not found')
    else
      @toggle_all_checkbox = @$container.find '.toggle_all'

    @checkboxes = @$container.find(':checkbox').not @toggle_all_checkbox

  _bind: ->
    @checkboxes.change       (e)=> @_didChangeCheckbox e.target
    @toggle_all_checkbox.change => @_didChangeToggleAllCheckbox()

  _didChangeCheckbox: (checkbox)->
    switch @checkboxes.filter(':checked').length
      when @checkboxes.length - 1 then @toggle_all_checkbox.prop checked: null
      when @checkboxes.length     then @toggle_all_checkbox.prop checked: true

  _didChangeToggleAllCheckbox: ->
    setting = if @toggle_all_checkbox.prop 'checked' then true else null
    @checkboxes.each (index, el)=>
      $(el).prop checked: setting
      @_didChangeCheckbox(el)

jQuery ($)->
  $.widget.bridge 'checkboxToggler', ActiveAdmin.CheckboxToggler

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
activeadmin-0.6.5 app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee
activeadmin-0.6.4 app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee
yousty-activeadmin-1.0.4.pre app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee
yousty-activeadmin-1.0.3.pre app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee
yousty-activeadmin-1.0.2.pre app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee
activeadmin-0.6.3 app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee
yousty-activeadmin-1.0.1.pre app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee
yousty-activeadmin-1.0.0.pre app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee
activeadmin-0.6.2 app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee
activeadmin-0.6.1 app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee