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

76 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import Component from '../../lib/component';
import './style.scss';
2018-02-10 15:18:01 +00:00
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;
2019-02-15 07:40:18 +00:00
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;
}
2019-02-15 07:49:44 +00:00
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;
2018-02-10 15:18:01 +00:00
}
2019-02-15 07:49:44 +00:00
if (!this.intermediate)
this.isIntermediate = false;
}
2018-02-10 15:18:01 +00:00
}
Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnCheck', {
template: require('./check.html'),
controller: Controller,
require: {
model: '?ngModel'
},
bindings: {
field: '=?',
label: '@?',
disabled: '<?',
checked: '<?',
tripleState: '<?',
intermediate: '<?'
}
});