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

76 lines
1.7 KiB
JavaScript

import ngModule from '../../module';
import Component from '../../lib/component';
import './style.scss';
export default class Controller extends Component {
constructor($element, $scope, $attrs) {
super($element, $scope);
this.hasInfo = Boolean($attrs.info);
this.info = $attrs.info || null;
}
set checkValue(value) {
this.checkIntermediate();
if (this.isIntermediate)
value = false;
this._field = value;
if (typeof this._checkValue === 'boolean')
this.emit('change', {value: this.field});
this._checkValue = value;
}
get checkValue() {
return this._checkValue;
}
set field(value) {
this.checkValue = value;
}
get field() {
if (!this._field && this.isIntermediate)
return null;
return this._field;
}
set tripleState(value) {
this._tripleState = value;
this.checkIntermediate();
}
get tripleState() {
return this._tripleState;
}
checkIntermediate() {
if ((this.intermediate || (!this._field && this.tripleState)) && !this.isIntermediate) {
this.isIntermediate = true;
return;
}
if (!this.intermediate)
this.isIntermediate = false;
}
}
Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnCheck', {
template: require('./check.html'),
controller: Controller,
require: {
model: '?ngModel'
},
bindings: {
field: '=?',
label: '@?',
disabled: '<?',
checked: '<?',
tripleState: '<?',
intermediate: '<?'
}
});