85 lines
2.5 KiB
JavaScript
85 lines
2.5 KiB
JavaScript
import ngModule from '../module';
|
|
import Component from 'core/lib/component';
|
|
|
|
class Controller extends Component {
|
|
constructor($element, $, $httpParamSerializer) {
|
|
super($element, $);
|
|
|
|
this.$httpParamSerializer = $httpParamSerializer;
|
|
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() {
|
|
const params = {
|
|
authorization: this.vnToken.token,
|
|
clientId: this.vnConfig.storage.currentUserWorkerId,
|
|
routeId: this.route.id
|
|
};
|
|
const serializedParams = this.$httpParamSerializer(params);
|
|
let url = `api/report/driver-route?${serializedParams}`;
|
|
window.open(url);
|
|
}
|
|
|
|
sendRouteReport() {
|
|
const params = {
|
|
recipient: user.emailUser.email,
|
|
clientId: this.vnConfig.storage.currentUserWorkerId,
|
|
routeId: this.route.id
|
|
};
|
|
this.$http.get(`email/driver-route`, {params}).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Report sent'));
|
|
});
|
|
}
|
|
|
|
showUpdateVolumeDialog() {
|
|
this.$.updateVolumeConfirmation.show();
|
|
}
|
|
|
|
updateVolume(response) {
|
|
if (response === 'accept') {
|
|
let url = `Routes/${this.route.id}/updateVolume`;
|
|
this.$http.post(url).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Volume updated'));
|
|
this.cardReload();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
|
|
|
|
ngModule.component('vnRouteDescriptor', {
|
|
template: require('./index.html'),
|
|
bindings: {
|
|
route: '<',
|
|
cardReload: '&?',
|
|
quicklinks: '<'
|
|
},
|
|
controller: Controller
|
|
});
|