178 lines
5.1 KiB
JavaScript
178 lines
5.1 KiB
JavaScript
import ngModule from '../module';
|
|
|
|
class Controller {
|
|
constructor($state, $scope, $http, vnApp, $translate) {
|
|
this.$scope = $scope;
|
|
this.$state = $state;
|
|
this.$http = $http;
|
|
this.vnApp = vnApp;
|
|
this.$translate = $translate;
|
|
this.moreOptions = [
|
|
{callback: this.showAddTurnDialog, name: 'Add turn', show: true},
|
|
{callback: this.showAddStowaway, name: 'Add stowaway', show: () => this.isTicketModule()},
|
|
{callback: this.showRemoveStowaway, name: 'Remove stowaway', show: () => this.shouldShowRemoveStowaway()},
|
|
/* {callback: this.showDeliveryNote, name: 'Show Delivery Note', show: true}, */
|
|
{callback: this.showDeleteTicketDialog, name: 'Delete ticket', show: true},
|
|
/* callback: this.showChangeShipped, name: 'Change shipped hour', show: true} */
|
|
];
|
|
}
|
|
|
|
// Change shipped hour
|
|
showChangeShipped() {
|
|
if (!this.isEditable) {
|
|
this.vnApp.showError(this.$translate.instant('This ticket can\'t be modified'));
|
|
return;
|
|
}
|
|
this.newShipped = new Date(this.ticket.shipped);
|
|
this.$scope.changeShippedDialog.show();
|
|
}
|
|
|
|
changeShipped(response) {
|
|
if (response === 'ACCEPT') {
|
|
let params = {shipped: this.newShipped};
|
|
this.$http.patch(`/ticket/api/Tickets/${this.ticket.id}/`, params).then(() => {
|
|
this.$state.go('ticket.index');
|
|
this.vnApp.showSuccess(this.$translate.instant('Shipped hour updated'));
|
|
});
|
|
}
|
|
}
|
|
|
|
isTicketModule() {
|
|
let path = this.$state.getCurrentPath();
|
|
if (path[1].state.name === 'ticket')
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
shouldShowRemoveStowaway() {
|
|
if (!this._ticket || !this.isTicketModule())
|
|
return false;
|
|
|
|
return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 0));
|
|
}
|
|
|
|
onMoreChange(callback) {
|
|
callback.call(this);
|
|
}
|
|
|
|
goToTicket(ticketID) {
|
|
this.$state.go('ticket.card.sale', {id: ticketID});
|
|
}
|
|
|
|
onMoreOpen() {
|
|
let options = this.moreOptions.filter(o => {
|
|
return o.show === true || typeof o.show === 'function' && o.show();
|
|
});
|
|
this.$scope.moreButton.data = options;
|
|
}
|
|
|
|
get isEditable() {
|
|
try {
|
|
return !this.ticket.tracking.state.alertLevel;
|
|
} catch (e) {}
|
|
|
|
return true;
|
|
}
|
|
|
|
// Add Turn
|
|
showAddTurnDialog() {
|
|
this.$scope.addTurn.show();
|
|
}
|
|
|
|
addTurn(day) {
|
|
let params = {ticketFk: this.ticket.id, weekDay: day};
|
|
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
|
|
this.$scope.addTurn.hide();
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
});
|
|
}
|
|
|
|
// Delete Ticket
|
|
showDeleteTicketDialog() {
|
|
if (!this.isEditable) {
|
|
this.vnApp.showError(this.$translate.instant('This ticket cant be deleted'));
|
|
return;
|
|
}
|
|
|
|
this.$scope.deleteConfirmation.show();
|
|
}
|
|
|
|
deleteTicket(response) {
|
|
if (response === 'ACCEPT') {
|
|
let params = {id: this.ticket.id};
|
|
this.$http.post(`/ticket/api/Tickets/deleted`, params).then(() => {
|
|
this.$state.go('ticket.index');
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
|
|
});
|
|
}
|
|
}
|
|
|
|
showAddStowaway() {
|
|
this.$scope.addStowaway.show();
|
|
}
|
|
|
|
showRemoveStowaway() {
|
|
this.$scope.removeStowaway.show();
|
|
}
|
|
|
|
get ticket() {
|
|
return this._ticket;
|
|
}
|
|
|
|
set ticket(value) {
|
|
this._ticket = value;
|
|
|
|
if (!value) return;
|
|
|
|
let links = {
|
|
btnOne: {
|
|
icon: 'person',
|
|
state: `client.card.summary({id: ${value.clientFk}})`,
|
|
tooltip: 'Client card'
|
|
}};
|
|
if (value.stowaway) {
|
|
links.btnTwo = {
|
|
icon: 'icon-stowaway',
|
|
state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
|
|
tooltip: 'Ship'
|
|
};
|
|
}
|
|
|
|
if (value.ship && value.ship.length == 1) {
|
|
links.btnThree = {
|
|
icon: 'icon-stowaway',
|
|
state: `ticket.card.summary({id: ${value.ship[0].id}})`,
|
|
tooltip: 'Stowaway'
|
|
};
|
|
} else if (value.ship && value.ship.length > 1)
|
|
this.shipStowaways = value.ship;
|
|
|
|
this._quicklinks = links;
|
|
}
|
|
|
|
set quicklinks(value = {}) {
|
|
this._quicklinks = Object.assign(value, this._quicklinks);
|
|
}
|
|
|
|
get quicklinks() {
|
|
return this._quicklinks;
|
|
}
|
|
|
|
showDeliveryNote() {
|
|
let url = `/api/report/rpt-delivery-note?ticketFk=${this.ticket.id}`;
|
|
window.open(url);
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate'];
|
|
|
|
ngModule.component('vnTicketDescriptor', {
|
|
template: require('./index.html'),
|
|
bindings: {
|
|
ticket: '<',
|
|
cardReload: '&'
|
|
},
|
|
controller: Controller
|
|
});
|