83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
import ngModule from '../module';
|
|
|
|
class Controller {
|
|
constructor($state, $scope, $http) {
|
|
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 => {
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
|
|
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: '<'
|
|
}
|
|
});
|