salix/modules/route/front/descriptor/index.js

90 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-03-22 10:07:44 +00:00
import ngModule from '../module';
class Controller {
constructor($, $http, vnApp, $translate, aclService, $httpParamSerializer) {
2019-04-15 12:34:33 +00:00
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
this.$ = $;
this.aclService = aclService;
this.$httpParamSerializer = $httpParamSerializer;
2019-04-15 12:34:33 +00:00
this.moreOptions = [
{callback: this.showRouteReport, name: 'Show route report'},
{callback: this.sendRouteReport, name: 'Send route report'},
{callback: this.showUpdateVolumeDialog, name: 'Update volume', acl: 'deliveryBoss'}
2019-04-15 12:34:33 +00:00
];
}
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;
}
2019-03-22 10:07:44 +00:00
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
2019-04-15 12:34:33 +00:00
onMoreChange(callback) {
callback.call(this);
}
showRouteReport() {
const user = this.route.worker.user;
const params = {
clientId: user.id,
routeId: this.route.id
};
const serializedParams = this.$httpParamSerializer(params);
let url = `api/report/driver-route?${serializedParams}`;
2019-04-15 12:34:33 +00:00
window.open(url);
}
sendRouteReport() {
const user = this.route.worker.user;
const params = {
recipient: user.emailUser.email,
clientId: user.id,
routeId: this.route.id
};
const serializedParams = this.$httpParamSerializer(params);
const url = `email/driver-route?${serializedParams}`;
this.$http.get(url).then(() => {
2019-04-15 12:34:33 +00:00
this.vnApp.showSuccess(this.$translate.instant('Report sent'));
});
}
showUpdateVolumeDialog() {
this.$.updateVolumeConfirmation.show();
}
updateVolume(response) {
2019-10-30 15:57:14 +00:00
if (response === 'accept') {
let url = `Routes/${this.route.id}/updateVolume`;
this.$http.post(url).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Volume updated'));
2020-02-07 06:43:22 +00:00
this.cardReload();
});
}
}
2019-03-22 10:07:44 +00:00
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', 'aclService', '$httpParamSerializer'];
2019-03-22 10:07:44 +00:00
ngModule.component('vnRouteDescriptor', {
template: require('./index.html'),
bindings: {
route: '<',
2020-02-07 06:43:22 +00:00
cardReload: '&?',
2019-03-22 10:07:44 +00:00
quicklinks: '<'
},
controller: Controller
});