import ngModule from '../module'; class Controller { constructor($, $http, vnApp, $translate, aclService) { this.$http = $http; this.vnApp = vnApp; this.$translate = $translate; this.$ = $; this.aclService = aclService; this.moreOptions = [ {callback: this.showRouteReport, name: 'Show route report'}, {callback: this.sendRouteReport, name: 'Send route report'}, {callback: this.showUpdateVolumeDialog, name: 'Update volume', acl: 'deliveryBoss'} ]; } 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; } set quicklinks(value = {}) { this._quicklinks = Object.assign(value, this._quicklinks); } get quicklinks() { return this._quicklinks; } onMoreChange(callback) { callback.call(this); } showRouteReport() { let url = `/api/report/rpt-route?routeFk=${this.route.id}`; window.open(url); } sendRouteReport() { let url = `/api/email/driver-route?routeFk=${this.route.id}`; this.$http.post(url).then(() => { this.vnApp.showSuccess(this.$translate.instant('Report sent')); }); } showUpdateVolumeDialog() { this.$.updateVolumeConfirmation.show(); } updateVolume(response) { if (response === 'ACCEPT') { let url = `/route/api/Routes/${this.route.id}/updateVolume`; this.$http.post(url).then(() => { this.vnApp.showSuccess(this.$translate.instant('Volume updated')); this.card.reload(); }); } } } Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', 'aclService']; ngModule.component('vnRouteDescriptor', { template: require('./index.html'), bindings: { route: '<', quicklinks: '<' }, require: { card: '^vnRouteCard' }, controller: Controller });