import ngModule from '../module'; import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { 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; }); } get isEditable() { try { return !this.ticket.ticketState.state.alertLevel; } catch (e) {} return true; } showInvoiceOutDescriptor(event, refFk) { if (!refFk) return; this.$.invoiceOutDescriptor.show(event.target, this.summary.invoiceOut.id); } setOkState() { let params = {}; if (this.$params.id) params = {ticketFk: this.$params.id}; if (!this.$params.id) params = {ticketFk: this.ticket.id}; params.code = 'OK'; this.$http.post(`TicketTrackings/changeState`, params).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); if (this.card) this.card.reload(); else { this.getSummary(); // Refresh index model if (this.model) this.model.refresh(); } }); } getRequestState(state) { switch (state) { case null: return 'New'; case false: return 'Denied'; case true: return 'Acepted'; } } } ngModule.vnComponent('vnTicketSummary', { template: require('./index.html'), controller: Controller, bindings: { ticket: '<', model: '