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

101 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-03-21 12:46:14 +00:00
import ngModule from '../module';
2020-03-17 14:24:55 +00:00
import Section from 'salix/components/section';
2019-03-21 12:46:14 +00:00
2020-03-17 14:24:55 +00:00
export default class Controller extends Section {
2020-08-25 08:00:21 +00:00
constructor($element, $, vnReport) {
super($element, $);
this.vnReport = vnReport;
this.droppableElement = 'a.vn-tr';
2020-08-25 08:00:21 +00:00
}
preview(route) {
2019-03-21 12:46:14 +00:00
this.routeSelected = route;
2019-03-22 10:10:23 +00:00
this.$.summary.show();
2019-03-21 12:46:14 +00:00
}
2020-08-25 08:00:21 +00:00
get checked() {
const rows = this.$.model.data || [];
const checkedRows = [];
for (let row of rows) {
if (row.checked)
checkedRows.push(row);
}
return checkedRows;
}
get totalChecked() {
return this.checked.length;
}
showRouteReport() {
const routes = [];
for (let route of this.checked)
routes.push(route.id);
const routesId = routes.join(',');
this.vnReport.show('driver-route', {
authorization: this.vnToken.token,
routeId: routesId
});
}
2020-12-24 10:31:20 +00:00
openClonationDialog() {
this.startedDate = new Date();
this.$.clonationDialog.show();
}
cloneSelectedRoutes() {
const routesIds = [];
for (let route of this.checked)
routesIds.push(route.id);
return this.$http.post('Routes/clone', {ids: routesIds, started: this.startedDate}).then(() => {
this.$.model.refresh();
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
onDrop($event) {
const target = $event.target;
const droppable = target.closest(this.droppableElement);
const ticketId = $event.dataTransfer.getData('Text');
const routeId = droppable.id;
if (isNaN(ticketId)) {
const regexp = new RegExp(/\/ticket\/([0-9]+)\//i);
const matches = ticketId.match(regexp);
if (matches && matches.length)
this.insert(routeId, matches[1]);
else
this.vnApp.showError(this.$t('Ticket not found'));
}
if (!isNaN(ticketId))
this.insert(routeId, ticketId);
}
insert(routeId, ticketId) {
routeId = parseInt(routeId);
ticketId = parseInt(ticketId);
const query = `Routes/${routeId}/insertTicket`;
return this.$http.patch(query, {ticketId}).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.$.model.refresh();
}).catch(error => {
if (error.status == 404)
return this.vnApp.showError(this.$t('Ticket not found'));
throw error;
});
}
2019-03-21 12:46:14 +00:00
}
2020-08-25 08:00:21 +00:00
Controller.$inject = ['$element', '$scope', 'vnReport'];
ngModule.vnComponent('vnRouteIndex', {
2019-03-21 12:46:14 +00:00
template: require('./index.html'),
controller: Controller
});