From a572130b6c9a84c4acac4e74bfba60a94c2dbbd1 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 30 Apr 2019 08:00:27 +0200 Subject: [PATCH] propagate check value to multicheck component for intermediate value #1305 --- ...d.spec.js => 04_edit_billing_data.spec.js} | 0 .../components/multi-check/multi-check.html | 6 +- .../components/multi-check/multi-check.js | 73 ++++++++++++++++--- front/core/locale/es.yml | 3 +- modules/route/front/tickets/index.html | 2 +- modules/ticket/front/index/index.html | 2 +- modules/ticket/front/sale/index.html | 2 +- 7 files changed, 73 insertions(+), 15 deletions(-) rename e2e/paths/02-client-module/{04_edit_pay_method.spec.js => 04_edit_billing_data.spec.js} (100%) diff --git a/e2e/paths/02-client-module/04_edit_pay_method.spec.js b/e2e/paths/02-client-module/04_edit_billing_data.spec.js similarity index 100% rename from e2e/paths/02-client-module/04_edit_pay_method.spec.js rename to e2e/paths/02-client-module/04_edit_billing_data.spec.js diff --git a/front/core/components/multi-check/multi-check.html b/front/core/components/multi-check/multi-check.html index 53c0262ed5..2d51324f07 100644 --- a/front/core/components/multi-check/multi-check.html +++ b/front/core/components/multi-check/multi-check.html @@ -1 +1,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/front/core/components/multi-check/multi-check.js b/front/core/components/multi-check/multi-check.js index 14c5d6a9a6..bb0279706c 100644 --- a/front/core/components/multi-check/multi-check.js +++ b/front/core/components/multi-check/multi-check.js @@ -12,21 +12,74 @@ export default class MultiCheck extends Input { super($element, $scope); this._checkAll = false; this.checkField = 'checked'; + this.isIntermediate = false; } - get checkAll() { - return this._checkAll; + /** + * Gets array model instance + * + * @return {ArrayModel} - Array model instance + */ + get model() { + return this._model; } - set checkAll(value) { - this._checkAll = value; - this.switchChecks(); + /** + * Sets the array model instance + * Changes intermediate property for + * the check component + * + * @param {ArrayModel} value - Array model instance + */ + set model(value) { + this._model = value; + + if (value) { + value.on('rowChange', () => { + this.isIntermediate = this.allChecked && !this.areAllChecked(); + if (this.isIntermediate) + this._checked = undefined; + else if (this.areAllChecked()) + this._checked = true; + }); + } } - switchChecks() { - if (!this.data) return; - this.data.forEach(el => { - el[this.checkField] = this._checkAll; + /** + * Returns a bolean result for + * checked instances + * + * @return {Boolean} - True if all instances are checked + */ + areAllChecked() { + if (!this.model || !this.model.data) return; + + const data = this.model.data; + return data.every(item => { + return item[this.checkField] === true; + }); + } + + /** + * Gets current check state + */ + get checked() { + return this._checked; + } + + /** + * Sets current check state + * + * @param {Boolean} value - Checkbox state [undefined, true, false] + */ + set checked(value) { + this._checked = value; + this.allChecked = value; + + const data = this.model.data; + if (!data) return; + data.forEach(el => { + el[this.checkField] = value; }); } } @@ -35,7 +88,7 @@ ngModule.component('vnMultiCheck', { template: require('./multi-check.html'), controller: MultiCheck, bindings: { - data: '=', + model: '<', checkField: ' + model="model"> Order diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index c5c82bc757..7cfbbf2441 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -36,7 +36,7 @@ + model="model"> diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 89848a99f3..d57c0b7c26 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -56,7 +56,7 @@ + model="model">