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
|
|
|
|
2019-02-15 12:31:14 +00:00
|
|
|
get model() {
|
|
|
|
return this._model;
|
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-02-15 12:31:14 +00:00
|
|
|
set model(value) {
|
|
|
|
if (value === null) return;
|
2019-02-15 07:02:29 +00:00
|
|
|
|
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 07:02:29 +00:00
|
|
|
|
2019-02-15 12:31:14 +00:00
|
|
|
this.emit('change', {value});
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-02-15 12:31:14 +00:00
|
|
|
this._model = value;
|
2019-02-14 19:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set field(value) {
|
2019-02-15 12:31:14 +00:00
|
|
|
if (typeof value === 'number')
|
|
|
|
value = Boolean(value);
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-02-15 12:31:14 +00:00
|
|
|
this._model = value;
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
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-12 12:16:49 +00:00
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
2019-02-15 12:31:14 +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,
|
2019-02-15 12:31:14 +00:00
|
|
|
|
2018-02-12 12:16:49 +00:00
|
|
|
bindings: {
|
|
|
|
field: '=?',
|
|
|
|
label: '@?',
|
|
|
|
disabled: '<?',
|
2019-02-14 19:17:22 +00:00
|
|
|
checked: '<?',
|
|
|
|
tripleState: '<?',
|
|
|
|
intermediate: '<?'
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
|
|
|
});
|