salix/client/core/src/multi-check/multi-check.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-06-26 08:52:22 +00:00
import {module} from '../module';
import './multi-check.scss';
export default class MultiCheck {
2017-06-26 11:53:52 +00:00
constructor($element, $document, $timeout) {
2017-06-26 08:52:22 +00:00
this.$element = $element;
2017-06-26 11:53:52 +00:00
this.$document = $document;
this.$timeout = $timeout;
2017-06-26 08:52:22 +00:00
this._checkAll = false;
2017-06-26 11:53:52 +00:00
this.type = {};
this.labelType = null;
this.showDropDown = false;
2017-06-26 08:52:22 +00:00
}
get checkAll() {
return this._checkAll;
}
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() {
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;
}
el.checked = checked;
}
);
2017-06-26 08:52:22 +00:00
}
2017-06-26 11:53:52 +00:00
$doCheck() {
if (this.type && this.type.id) {
switch (this.type.id) {
case 'all':
this.labelType = null;
this.checkAll = true;
break;
case 'any':
this.labelType = null;
this.checkAll = false;
break;
default:
this.labelType = this.type.id;
this.checkAll = false;
break;
}
this.type = {};
}
2017-06-26 08:52:22 +00:00
}
}
2017-06-26 11:53:52 +00:00
MultiCheck.$inject = ['$element', '$document', '$timeout'];
2017-06-26 08:52:22 +00:00
module.component('vnMultiCheck', {
template: require('./multi-check.html'),
controller: MultiCheck,
bindings: {
options: '<',
container: '@',
2017-06-26 11:53:52 +00:00
models: '=',
2017-06-26 08:52:22 +00:00
className: '@?'
}
});