salix/modules/item/front/ticket-descriptor/removeStowaway.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

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(`/api/Stowaways?filter=${json}`).then(res => {
this.ticketStowaways = res.data;
this.$scope.dialog.show();
});
}
}
deleteStowaway(response) {
if (response === 'ACCEPT') {
this.$http.delete(`/api/Stowaways/${this.stowawayToDelete.id}`).then(res => {
this.card.reload();
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: '<'
},
require: {
card: '^vnTicketCard'
}
});