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

103 lines
2.7 KiB
JavaScript

import ngModule from '../module';
import Descriptor from 'salix/components/descriptor';
class Controller extends Descriptor {
get route() {
return this.entity;
}
set route(value) {
this.entity = value;
}
showRouteReport() {
this.vnReport.show(`Routes/${this.id}/driver-route-pdf`, {
id: this.id
});
}
sendRouteReport() {
const workerUser = this.route.worker.user;
this.vnEmail.send(`Routes/${this.id}/driver-route-email`, {
recipient: workerUser.emailUser.email,
id: this.id
});
}
updateVolume() {
this.$http.post(`Routes/${this.id}/updateVolume`)
.then(() => {
if (this.cardReload) this.cardReload();
this.vnApp.showSuccess(this.$t('Volume updated'));
});
}
loadData() {
const filter = {
fields: [
'id',
'workerFk',
'agencyModeFk',
'created',
'm3',
'warehouseFk',
'description',
'vehicleFk',
'kmStart',
'kmEnd',
'started',
'finished',
'cost',
'zoneFk'
],
include: [
{
relation: 'agencyMode',
scope: {
fields: ['id', 'name']
}
}, {
relation: 'vehicle',
scope: {
fields: ['id', 'm3']
}
}, {
relation: 'zone',
scope: {
fields: ['id', 'name']
}
}, {
relation: 'worker',
scope: {
fields: ['userFk'],
include: {
relation: 'user',
scope: {
fields: ['id'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}
}
}
]
};
return this.getData(`Routes/${this.id}`, {filter})
.then(res => this.entity = res.data);
}
}
ngModule.vnComponent('vnRouteDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
route: '<',
cardReload: '&?'
}
});