From 84bacfd37993e1236d4818ce0e963b9c05c499b4 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 18 Jun 2020 10:10:42 +0200 Subject: [PATCH 1/3] add message before delete a line on a claim --- modules/claim/front/detail/index.html | 7 ++++++- modules/claim/front/detail/index.js | 22 ++++++++++++++-------- modules/claim/front/detail/index.spec.js | 8 +++++--- modules/claim/front/detail/locale/es.yml | 3 ++- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html index 9af8fd328..56dbc3c53 100644 --- a/modules/claim/front/detail/index.html +++ b/modules/claim/front/detail/index.html @@ -69,7 +69,7 @@ vn-tooltip="Remove sale" ng-if ="$ctrl.isRewritable" icon="delete" - ng-click="$ctrl.deleteClaimedSale($index)" + ng-click="$ctrl.showDeleteConfirm($index)" tabindex="-1"> @@ -165,3 +165,8 @@ + + \ No newline at end of file diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index d84090e52..8237241df 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -73,14 +73,20 @@ class Controller extends Section { }); } - deleteClaimedSale(index) { - let sale = this.salesClaimed[index]; - let query = `ClaimBeginnings/${sale.id}`; - this.$http.delete(query).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$.model.remove(index); - this.calculateTotals(); - }); + showDeleteConfirm(index) { + this.sale = this.salesClaimed[index]; + this.$.confirm.show(); + } + + deleteClaimedSale(response) { + if (response === 'accept') { + let query = `ClaimBeginnings/${this.sale.id}`; + this.$http.delete(query).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.model.remove(this.sale); + this.calculateTotals(); + }); + } } setClaimedQuantity(id, claimedQuantity) { diff --git a/modules/claim/front/detail/index.spec.js b/modules/claim/front/detail/index.spec.js index 5004ba7a1..520f40f39 100644 --- a/modules/claim/front/detail/index.spec.js +++ b/modules/claim/front/detail/index.spec.js @@ -71,14 +71,16 @@ describe('claim', () => { }); }); - describe('deleteClaimedSale(index)', () => { + describe('deleteClaimedSale()', () => { it('should make a delete and call refresh and showSuccess', () => { + controller.sale = {id: 1}; jest.spyOn(controller.$.model, 'remove'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectDELETE(`ClaimBeginnings/1`).respond({}); - controller.deleteClaimedSale(0); + controller.deleteClaimedSale('accept'); $httpBackend.flush(); - expect(controller.$.model.remove).toHaveBeenCalledWith(0); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); }); }); diff --git a/modules/claim/front/detail/locale/es.yml b/modules/claim/front/detail/locale/es.yml index 9bbfd7e86..53f9e9b1d 100644 --- a/modules/claim/front/detail/locale/es.yml +++ b/modules/claim/front/detail/locale/es.yml @@ -7,4 +7,5 @@ Claimable sales from ticket: Lineas reclamables del ticket Detail: Detalles Add sale item: Añadir artículo Insuficient permisos: Permisos insuficientes -Total claimed price: Precio total reclamado \ No newline at end of file +Total claimed price: Precio total reclamado +Delete sale from claim?: ¿Borrar la linea de la reclamación? \ No newline at end of file From 2275541bb185717048538e08163d6049aca6af73 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 23 Jun 2020 12:46:24 +0200 Subject: [PATCH 2/3] change on-response for on-accept --- modules/claim/front/detail/index.html | 2 +- modules/claim/front/detail/index.js | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html index 56dbc3c53..e364801bf 100644 --- a/modules/claim/front/detail/index.html +++ b/modules/claim/front/detail/index.html @@ -168,5 +168,5 @@ + on-accept="$ctrl.deleteClaimedSale()"> \ No newline at end of file diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index 8237241df..7719a9fc9 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -78,15 +78,13 @@ class Controller extends Section { this.$.confirm.show(); } - deleteClaimedSale(response) { - if (response === 'accept') { - let query = `ClaimBeginnings/${this.sale.id}`; - this.$http.delete(query).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$.model.remove(this.sale); - this.calculateTotals(); - }); - } + deleteClaimedSale() { + let query = `ClaimBeginnings/${this.sale.id}`; + this.$http.delete(query).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.model.remove(this.sale); + this.calculateTotals(); + }); } setClaimedQuantity(id, claimedQuantity) { From ec6a3e00f75f21ead47990b33ddd836f286b9a64 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 23 Jun 2020 13:26:21 +0200 Subject: [PATCH 3/3] removed unused argument in test --- modules/claim/front/detail/index.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/claim/front/detail/index.spec.js b/modules/claim/front/detail/index.spec.js index 520f40f39..5061eaff7 100644 --- a/modules/claim/front/detail/index.spec.js +++ b/modules/claim/front/detail/index.spec.js @@ -76,8 +76,8 @@ describe('claim', () => { controller.sale = {id: 1}; jest.spyOn(controller.$.model, 'remove'); jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expectDELETE(`ClaimBeginnings/1`).respond({}); - controller.deleteClaimedSale('accept'); + $httpBackend.expectDELETE(`ClaimBeginnings/1`).respond('ok'); + controller.deleteClaimedSale(); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');