Merge branch 'dev' into jgallego

This commit is contained in:
Gerard 2019-02-15 13:33:24 +01:00
commit b01f401286
3 changed files with 29 additions and 39 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;
}
checkIntermediate() {
if ((this.intermediate || (!this._field && this.tripleState)) && !this.isIntermediate) {
this.isIntermediate = true;
return;
}
if (!this.intermediate)
this.isIntermediate = false;
get isChecked() {
return this.checked || this.model === true;
}
}
Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnCheck', {
template: require('./check.html'),
controller: Controller,
require: {
model: '?ngModel'
},
bindings: {
field: '=?',
label: '@?',

View File

@ -21,7 +21,7 @@ describe('Ticket', () => {
$state.params.id = 1;
controller = $componentController('vnTicketSaleEditDiscount', {$scope, $state});
controller._edit = [{id: 3, discount: 15}];
controller.hide = () => {};
controller.onHide = () => {};
}));
describe('edit() setter', () => {