Sha256: 037d7bd6497a2740322267b311c5fe1d5ecb568e59ad4f917182418407b61eca

Contents?: true

Size: 1.38 KB

Versions: 17

Compression:

Stored size: 1.38 KB

Contents

ActiveAdmin.CheckboxToggler = class CheckboxToggler {
  constructor(options, container){
    this.options = options;
    this.container = container;
    this._init();
    this._bind();
  }

  option(key, value) {
  }

  _init() {
    if (!this.container) {
      throw new Error('Container element not found');
    } else {
      this.$container = $(this.container);
    }

    if (!this.$container.find('.toggle_all').length) {
      throw new Error('"toggle all" checkbox not found');
    } else {
      this.toggle_all_checkbox = this.$container.find('.toggle_all');
    }

    this.checkboxes = this.$container.find(':checkbox').not(this.toggle_all_checkbox);
  }

  _bind() {
    this.checkboxes.change(event => this._didChangeCheckbox(event.target));
    this.toggle_all_checkbox.change(() => this._didChangeToggleAllCheckbox());
  }

  _didChangeCheckbox(checkbox){
    const numChecked = this.checkboxes.filter(':checked').length;

    const allChecked = numChecked === this.checkboxes.length;
    const someChecked = (numChecked > 0) && (numChecked < this.checkboxes.length);

    this.toggle_all_checkbox.prop({ checked: allChecked, indeterminate: someChecked });
  }

  _didChangeToggleAllCheckbox() {
    const setting = this.toggle_all_checkbox.prop('checked');
    this.checkboxes.prop({ checked: setting });
    return setting;
  }
};

$.widget.bridge('checkboxToggler', ActiveAdmin.CheckboxToggler);

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
activeadmin-rails-1.7.1 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-rails-1.7.0 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.4.0 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.3.1 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.3.0 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.2.0 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.1.0 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.0.0 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.0.0.rc2 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin-2.0.0.rc1 app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/checkbox-toggler.es6