import ngModule from '../module'; import './style.scss'; class Controller { constructor($scope, $state, $http, vnApp, $translate) { this.$scope = $scope; this.vnApp = vnApp; this.$translate = $translate; this.$http = $http; this.$state = $state; } get ticket() { return this._ticket; } set ticket(value) { this._ticket = value; if (value) this.getSummary(); } get formattedAddress() { if (!this.summary) return; let address = this.summary.address; let province = address.province ? `(${address.province.name})` : ''; return `${address.street} - ${address.city} ${province}`; } getSummary() { this.$http.get(`Tickets/${this.ticket.id}/summary`).then(res => { if (res && res.data) this.summary = res.data; }); } showDescriptor(event, itemFk) { this.quicklinks = { btnThree: { icon: 'icon-transaction', state: `item.card.diary({ id: ${itemFk}, warehouseFk: ${this.ticket.warehouseFk}, ticketFk: ${this.ticket.id} })`, tooltip: 'Item diary' } }; this.$scope.descriptor.itemFk = itemFk; this.$scope.descriptor.parent = event.target; this.$scope.descriptor.show(); } onDescriptorLoad() { this.$scope.popover.relocate(); } get isEditable() { try { return !this.ticket.state.state.alertLevel; } catch (e) {} return true; } setOkState() { let params = {}; if (this.$state.params.id) params = {ticketFk: this.$state.params.id}; if (!this.$state.params.id) params = {ticketFk: this.ticket.id}; params.code = 'OK'; this.$http.post(`TicketTrackings/changeState`, params).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); if (this.card) this.card.reload(); else this.getSummary(); }); } getRequestState(state) { switch (state) { case null: return 'New'; case false: return 'Denied'; case true: return 'Acepted'; } } } Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; ngModule.component('vnTicketSummary', { template: require('./index.html'), controller: Controller, bindings: { ticket: '<' }, require: { card: '?^vnTicketCard' } });