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

66 lines
1.4 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;
}
2019-02-15 12:31:14 +00:00
get model() {
return this._model;
}
2019-02-15 12:31:14 +00:00
set model(value) {
if (value === null) return;
2019-02-15 12:31:14 +00:00
if (this.model === true)
value = false;
else if (this.model === false && this.tripleState)
value = null;
2019-02-15 12:31:14 +00:00
this.emit('change', {value});
2019-02-15 12:31:14 +00:00
this._model = value;
}
set field(value) {
2019-02-15 12:31:14 +00:00
if (typeof value === 'number')
value = Boolean(value);
2019-02-15 12:31:14 +00:00
this._model = value;
}
2019-02-15 12:31:14 +00:00
get field() {
return this._model;
2019-02-15 07:49:44 +00:00
}
2019-02-15 12:31:14 +00:00
get isIntermediate() {
return this.intermediate
|| this.model === null
|| this.model === undefined;
2019-02-15 07:49:44 +00:00
}
2019-02-15 12:31:14 +00:00
get isChecked() {
return this.checked || this.model === true;
}
2018-02-10 15:18:01 +00:00
}
2019-02-15 12:31:14 +00:00
Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnCheck', {
template: require('./check.html'),
controller: Controller,
2019-02-15 12:31:14 +00:00
bindings: {
field: '=?',
label: '@?',
disabled: '<?',
checked: '<?',
tripleState: '<?',
intermediate: '<?'
}
});