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

45 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import Input from '../../lib/input';
2018-02-10 15:18:01 +00:00
/**
* 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';
}
2017-06-26 08:52:22 +00:00
get checkAll() {
return this._checkAll;
}
2017-06-26 08:52:22 +00:00
set checkAll(value) {
this._checkAll = value;
2017-06-26 11:53:52 +00:00
this.switchChecks();
2017-06-26 08:52:22 +00:00
}
2017-06-26 11:53:52 +00:00
switchChecks() {
if (!this.data) return;
this.data.forEach(el => {
el[this.checkField] = this._checkAll;
});
2017-10-19 12:13:28 +00:00
}
2017-06-26 08:52:22 +00:00
}
2018-02-10 15:18:01 +00:00
ngModule.component('vnMultiCheck', {
2017-06-26 08:52:22 +00:00
template: require('./multi-check.html'),
controller: MultiCheck,
bindings: {
data: '=',
checkField: '<?',
checkAll: '=?',
disabled: '<?'
2017-06-26 08:52:22 +00:00
}
});