import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { constructor($element, $, $httpParamSerializer) { super($element, $); this.$httpParamSerializer = $httpParamSerializer; this.moreOptions = [ {callback: this.showPickupOrder, name: 'Show Pickup order'}, {callback: this.confirmPickupOrder, name: 'Send Pickup order'}, {callback: this.confirmDeleteClaim, name: 'Delete claim', acl: 'salesAssistant'} ]; } onMoreOpen() { let options = this.moreOptions.filter(option => { const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); }); this.$.moreButton.data = options; } onMoreChange(callback) { callback.call(this); } get claim() { return this._claim; } set claim(value) { this._claim = value; if (!value) return; this._quicklinks = { btnOne: { icon: 'person', state: `client.card.summary({id: ${value.clientFk}})`, tooltip: 'Client card' }, btnTwo: { icon: 'icon-ticket', state: `ticket.card.summary({id: ${this.claim.ticketFk}})`, tooltip: 'Claimed ticket' } }; } showPickupOrder() { const params = { clientId: this.claim.clientFk, claimId: this.claim.id, authorization: this.vnToken.token }; const serializedParams = this.$httpParamSerializer(params); let url = `api/report/claim-pickup-order?${serializedParams}`; window.open(url); } confirmPickupOrder() { this.$.confirmPickupOrder.show(); } sendPickupOrder(response) { if (response === 'accept') { const params = { recipient: this.claim.client.email, clientId: this.claim.clientFk, claimId: this.claim.id }; this.$http.get(`email/claim-pickup-order`, {params}).then( () => this.vnApp.showMessage(this.$t('Notification sent!')) ); } } confirmDeleteClaim() { this.$.confirmDeleteClaim.show(); } deleteClaim(response) { if (response === 'accept') { this.$http.delete(`Claims/${this.claim.id}`).then(() => { this.vnApp.showSuccess(this.$translate.instant('Claim deleted!')); this.$state.go('claim.index'); }); } } } Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; ngModule.vnComponent('vnClaimDescriptor', { template: require('./index.html'), controller: Controller, bindings: { claim: '<', tags: '<' } });