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'}, {callback: this.showDeleteTicketDialog, name: 'Delete ticket'} ]; } onMoreChange(callback) { callback.call(this); } 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')); }); } } get ticket() { return this._ticket; } set ticket(value) { this._ticket = value; if (!value) return; this._quicklinks = { btnOne: { icon: 'person', state: `client.card.summary({id: ${value.clientFk}})`, tooltip: 'Client card' } }; } set quicklinks(value = {}) { this._quicklinks = Object.assign(value, this._quicklinks); } get quicklinks() { return this._quicklinks; } } Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate']; ngModule.component('vnTicketDescriptor', { template: require('./index.html'), bindings: { ticket: '<' }, controller: Controller });