salix/front/core/components/multi-check/multi-check.js

45 lines
1.0 KiB
JavaScript

import ngModule from '../../module';
import Input from '../../lib/input';
/**
* Draw checkbox with a drop-down and multi options
* @param {SmallInt} checkAll Primary input-check state: 0 -> uncheck, 1 -> checked
* @param {Array} data List of options shown in drop-down
* @param {Array} models Elements to check / unCheck
*/
export default class MultiCheck extends Input {
constructor($element, $scope) {
super($element, $scope);
this._checkAll = false;
this.checkField = 'checked';
}
get checkAll() {
return this._checkAll;
}
set checkAll(value) {
this._checkAll = value;
this.switchChecks();
}
switchChecks() {
if (!this.data) return;
this.data.forEach(el => {
el[this.checkField] = this._checkAll;
});
}
}
ngModule.component('vnMultiCheck', {
template: require('./multi-check.html'),
controller: MultiCheck,
bindings: {
data: '=',
checkField: '<?',
checkAll: '=?',
disabled: '<?'
}
});