From d648db504cec9d28d3c37c4f3321eb31cfed54c4 Mon Sep 17 00:00:00 2001 From: Gerard Date: Fri, 1 Feb 2019 12:11:56 +0100 Subject: [PATCH] added card.reload and fixed remove stowaway not showing --- .../front/ticket-descriptor/addStowaway.js | 13 +++++++++---- modules/item/front/ticket-descriptor/index.js | 3 ++- .../front/ticket-descriptor/removeStowaway.js | 18 ++++++++---------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/item/front/ticket-descriptor/addStowaway.js b/modules/item/front/ticket-descriptor/addStowaway.js index 259d930503..b1e5308502 100644 --- a/modules/item/front/ticket-descriptor/addStowaway.js +++ b/modules/item/front/ticket-descriptor/addStowaway.js @@ -1,7 +1,9 @@ import ngModule from '../module'; class Controller { - constructor($state, $scope, $http) { + constructor($state, $scope, $http, vnApp, $translate) { + this.vnApp = vnApp; + this.$translate = $translate; this.$scope = $scope; this.$state = $state; this.$http = $http; @@ -17,9 +19,9 @@ class Controller { addStowaway(index) { let params = {id: this.possibleStowaways[index].id, shipFk: this.ticket.id}; this.$http.post(`/api/Stowaways/`, params) - .then(res => { - this.ticket.ship.push = res.data[0]; - this.hide; + .then(() => { + this.card.reload(); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }); } @@ -39,5 +41,8 @@ ngModule.component('vnAddStowaway', { controller: Controller, bindings: { ticket: '<' + }, + require: { + card: '^vnTicketCard' } }); diff --git a/modules/item/front/ticket-descriptor/index.js b/modules/item/front/ticket-descriptor/index.js index 5299760e28..91e323ff83 100644 --- a/modules/item/front/ticket-descriptor/index.js +++ b/modules/item/front/ticket-descriptor/index.js @@ -40,7 +40,8 @@ class Controller { shouldShowRemoveStowaway() { if (!this._ticket) return false; - return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 1)); + + return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 0)); } onMoreChange(callback) { diff --git a/modules/item/front/ticket-descriptor/removeStowaway.js b/modules/item/front/ticket-descriptor/removeStowaway.js index f152d3bdf1..6d4e966bfe 100644 --- a/modules/item/front/ticket-descriptor/removeStowaway.js +++ b/modules/item/front/ticket-descriptor/removeStowaway.js @@ -1,7 +1,9 @@ import ngModule from '../module'; class Controller { - constructor($state, $scope, $http) { + constructor($state, $scope, $http, vnApp, $translate) { + this.vnApp = vnApp; + this.$translate = $translate; this.$scope = $scope; this.$state = $state; this.$http = $http; @@ -44,15 +46,8 @@ class Controller { deleteStowaway(response) { if (response === 'ACCEPT') { this.$http.delete(`/api/Stowaways/${this.stowawayToDelete.id}`).then(res => { - if (this.ticket.stowaway) - delete this.ticket.stowaway; - else { - for (let i = 0; i < this.ticket.ship.length; i++) { - if (this.ticket.ship[i].id === this.stowawayToDelete.id) - delete this.ticket.ship[i]; - } - } - this.hide(); + this.card.reload(); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }); } } @@ -78,5 +73,8 @@ ngModule.component('vnRemoveStowaway', { controller: Controller, bindings: { ticket: '<' + }, + require: { + card: '^vnTicketCard' } });