import ngModule from '../module'; class Controller { constructor($state, $scope, $http, vnApp, $translate) { this.vnApp = vnApp; this.$translate = $translate; this.$scope = $scope; this.$state = $state; this.$http = $http; } getTicketStowaways() { if (this.ticket.stowaway) { this.ticketStowaways = [this.ticket.stowaway]; this.showDeleteConfirm(0); } else if (this.ticket.ship.length > 1) { let filter = { where: {shipFk: this.ticket.id}, include: { relation: 'ticket', scope: { include: [ {relation: 'agencyMode'}, {relation: 'warehouse'}, {relation: 'state', scope: { fields: ['stateFk'], include: { relation: 'state' } }, }, ] } } }; let json = encodeURIComponent(JSON.stringify(filter)); this.$http.get(`Stowaways?filter=${json}`).then(res => { this.ticketStowaways = res.data; this.$scope.dialog.show(); }); } } deleteStowaway(response) { if (response === 'accept') { this.$http.delete(`Stowaways/${this.stowawayToDelete.id}`).then(res => { this.cardReload(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }); } } showDeleteConfirm(index) { this.stowawayToDelete = this.ticketStowaways[index]; this.$scope.confirmationDialog.show(); } show() { this.getTicketStowaways(); } hide() { this.$scope.dialog.hide(); } } Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate']; ngModule.component('vnRemoveStowaway', { template: require('./removeStowaway.html'), controller: Controller, bindings: { ticket: '<', cardReload: '&?' } });