Current section
Files
Jump to
Current section
Files
web/static/vendor/active_admin/lib/checkbox-toggler.js.js
// Generated by CoffeeScript 1.10.0
(function() {
ActiveAdmin.CheckboxToggler = (function() {
function CheckboxToggler(options, container) {
var defaults;
this.options = options;
this.container = container;
defaults = {};
this.options = $.extend(defaults, this.options);
this._init();
this._bind();
}
CheckboxToggler.prototype._init = function() {
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');
}
return this.checkboxes = this.$container.find(':checkbox').not(this.toggle_all_checkbox);
};
CheckboxToggler.prototype._bind = function() {
this.checkboxes.change((function(_this) {
return function(e) {
return _this._didChangeCheckbox(e.target);
};
})(this));
return this.toggle_all_checkbox.change((function(_this) {
return function() {
return _this._didChangeToggleAllCheckbox();
};
})(this));
};
CheckboxToggler.prototype._didChangeCheckbox = function(checkbox) {
switch (this.checkboxes.filter(':checked').length) {
case this.checkboxes.length - 1:
return this.toggle_all_checkbox.prop({
checked: null
});
case this.checkboxes.length:
return this.toggle_all_checkbox.prop({
checked: true
});
}
};
CheckboxToggler.prototype._didChangeToggleAllCheckbox = function() {
var setting;
setting = this.toggle_all_checkbox.prop('checked') ? true : null;
return this.checkboxes.each((function(_this) {
return function(index, el) {
$(el).prop({
checked: setting
});
return _this._didChangeCheckbox(el);
};
})(this));
};
return CheckboxToggler;
})();
$.widget.bridge('checkboxToggler', ActiveAdmin.CheckboxToggler);
}).call(this);