2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2019-02-15 07:02:29 +00:00
|
|
|
import Component from '../../lib/component';
|
2018-02-12 12:16:49 +00:00
|
|
|
import './style.scss';
|
2018-02-10 15:18:01 +00:00
|
|
|
|
2019-02-15 07:02:29 +00:00
|
|
|
export default class Controller extends Component {
|
|
|
|
constructor($element, $scope, $attrs) {
|
|
|
|
super($element, $scope);
|
2018-12-11 11:57:07 +00:00
|
|
|
this.hasInfo = Boolean($attrs.info);
|
|
|
|
this.info = $attrs.info || null;
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
|
|
|
set checkValue(value) {
|
|
|
|
this.checkIntermediate();
|
|
|
|
if (this.isIntermediate)
|
|
|
|
value = false;
|
|
|
|
|
2018-10-15 09:43:57 +00:00
|
|
|
this._field = value;
|
2019-02-15 07:02:29 +00:00
|
|
|
|
|
|
|
if (this._checkValue !== undefined && this._checkValue !== null)
|
|
|
|
this.emit('change', {value: this.field});
|
|
|
|
|
2019-02-14 19:17:22 +00:00
|
|
|
this._checkValue = value;
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
|
|
|
get checkValue() {
|
|
|
|
return this._checkValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
set field(value) {
|
|
|
|
this.checkValue = value;
|
|
|
|
}
|
|
|
|
|
2018-02-12 12:16:49 +00:00
|
|
|
get field() {
|
2019-02-14 19:17:22 +00:00
|
|
|
if (!this._field && this.isIntermediate)
|
|
|
|
return null;
|
|
|
|
|
2018-10-15 09:43:57 +00:00
|
|
|
return this._field;
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
|
|
|
checkIntermediate() {
|
2019-02-15 07:02:29 +00:00
|
|
|
if ((this.intermediate || (!this._field && this.tripleState)) && !this.isIntermediate) {
|
2019-02-14 19:17:22 +00:00
|
|
|
this.isIntermediate = true;
|
|
|
|
return;
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
|
|
|
this.isIntermediate = false;
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
2019-02-15 07:02:29 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', '$attrs'];
|
2018-02-12 12:16:49 +00:00
|
|
|
|
|
|
|
ngModule.component('vnCheck', {
|
|
|
|
template: require('./check.html'),
|
|
|
|
controller: Controller,
|
|
|
|
require: {
|
|
|
|
model: '?ngModel'
|
|
|
|
},
|
|
|
|
bindings: {
|
|
|
|
field: '=?',
|
|
|
|
label: '@?',
|
|
|
|
disabled: '<?',
|
2019-02-14 19:17:22 +00:00
|
|
|
checked: '<?',
|
|
|
|
tripleState: '<?',
|
|
|
|
intermediate: '<?'
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
|
|
|
});
|