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

65 lines
1.3 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-19 06:04:56 +00:00
if (this.model === false && this.tripleState)
2019-02-15 12:31:14 +00:00
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() {
if (this.intermediate || (this.tripleState && (this.model === null || this.model === undefined)))
return true;
return false;
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: '<?'
}
});