import {module} from '../module'; import './multi-check.scss'; export default class MultiCheck { constructor() { this._checkAll = 0; this.type = {}; this.labelType = null; this.showDropDown = false; } get checkAll() { return this._checkAll; } set checkAll(value) { this._checkAll = value; this.switchChecks(); } switchChecks() { this.models.forEach( el => { let checked; if (this.labelType) { if (this.labelType.length > 3 && this.labelType.substr(0, 3) === 'no-') { checked = el[this.labelType.replace('no-', '')] ? false : true; } else { checked = el[this.labelType] ? true : false; } } else { checked = this.checkAll === 1; } el.checked = checked; } ); } $doCheck() { if (this.type && this.type.id) { switch (this.type.id) { case 'all': this.labelType = null; this.checkAll = 1; break; case 'any': this.labelType = null; this.checkAll = 0; break; default: this.labelType = this.type.id; this.checkAll = 2; break; } this.type = {}; this.labelType = null; } } } MultiCheck.$inject = []; module.component('vnMultiCheck', { template: require('./multi-check.html'), controller: MultiCheck, bindings: { options: '<', models: '=', className: '@?' } });