updated check component

This commit is contained in:
Joan Sanchez 2019-02-15 13:31:14 +01:00
parent 8bea3afbfb
commit 08c252fb9b
2 changed files with 28 additions and 38 deletions

View File

@ -2,8 +2,8 @@
aria-label="Checkbox 1"
md-indeterminate="$ctrl.isIntermediate"
ng-disabled="$ctrl.disabled"
ng-checked="$ctrl.checkValue"
ng-model="$ctrl.checkValue">
ng-checked="$ctrl.isChecked"
ng-model="$ctrl.model">
<span translate>{{::$ctrl.label}}</span>
</md-checkbox>
<i class="material-icons"

View File

@ -9,61 +9,51 @@ export default class Controller extends Component {
this.info = $attrs.info || null;
}
set checkValue(value) {
this.checkIntermediate();
if (this.isIntermediate)
value = false;
this._field = value;
if (typeof this._checkValue === 'boolean')
this.emit('change', {value: this.field});
this._checkValue = value;
get model() {
return this._model;
}
get checkValue() {
return this._checkValue;
set model(value) {
if (value === null) return;
if (this.model === true)
value = false;
else if (this.model === false && this.tripleState)
value = null;
this.emit('change', {value});
this._model = value;
}
set field(value) {
this.checkValue = value;
if (typeof value === 'number')
value = Boolean(value);
this._model = value;
}
get field() {
if (!this._field && this.isIntermediate)
return null;
return this._field;
return this._model;
}
set tripleState(value) {
this._tripleState = value;
this.checkIntermediate();
get isIntermediate() {
return this.intermediate
|| this.model === null
|| this.model === undefined;
}
get tripleState() {
return this._tripleState;
get isChecked() {
return this.checked || this.model === true;
}
}
checkIntermediate() {
if ((this.intermediate || (!this._field && this.tripleState)) && !this.isIntermediate) {
this.isIntermediate = true;
return;
}
if (!this.intermediate)
this.isIntermediate = false;
}
}
Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnCheck', {
template: require('./check.html'),
controller: Controller,
require: {
model: '?ngModel'
},
bindings: {
field: '=?',
label: '@?',