112 lines
3.2 KiB
JavaScript
112 lines
3.2 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
class Controller {
|
|
constructor($stateParams, $, $translate, $http, vnApp) {
|
|
this.$translate = $translate;
|
|
this.$stateParams = $stateParams;
|
|
this.$ = $;
|
|
this.$http = $http;
|
|
this.vnApp = vnApp;
|
|
}
|
|
|
|
get isChecked() {
|
|
if (this.tickets) {
|
|
for (let instance of this.tickets)
|
|
if (instance.checked) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
getHighestPriority() {
|
|
let max = 0;
|
|
this.$.model.data.forEach(tag => {
|
|
if (tag.priority > max)
|
|
max = tag.priority;
|
|
});
|
|
return max + 1;
|
|
}
|
|
|
|
setPriority(id, priority) {
|
|
let params = {priority: priority};
|
|
let query = `/api/Tickets/${id}/`;
|
|
this.$http.patch(query, params).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
this.$.model.refresh();
|
|
});
|
|
}
|
|
|
|
getCheckedLines() {
|
|
let lines = [];
|
|
let data = this.tickets;
|
|
if (data) {
|
|
for (let i = 0; i < data.length; i++) {
|
|
if (data[i].checked)
|
|
lines.push(data[i]);
|
|
}
|
|
}
|
|
return lines;
|
|
}
|
|
|
|
goToBuscaman() {
|
|
// firstAddress is a temporal variable, will be replaced with #1298
|
|
let firstAddress = `46460 Av Espioca 100-46460 Silla`;
|
|
let addresses = firstAddress;
|
|
|
|
let lines = this.getCheckedLines();
|
|
|
|
let url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
|
|
lines.forEach(line => {
|
|
addresses = addresses + '+to:' + line.address.postalCode + ' ' + line.address.street + '-' + line.address.postalCode + ' ' + line.address.city;
|
|
});
|
|
|
|
window.open(url + addresses, '_blank');
|
|
}
|
|
|
|
showDeleteConfirm(ticket) {
|
|
this.selectedTicket = ticket;
|
|
this.$.confirm.show();
|
|
}
|
|
|
|
deleteFromRoute(response) {
|
|
if (response === 'ACCEPT') {
|
|
let params = {routeFk: null};
|
|
let query = `/api/Tickets/${this.selectedTicket}/`;
|
|
this.$http.patch(query, params).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted from route'));
|
|
this.$.model.refresh();
|
|
});
|
|
}
|
|
}
|
|
|
|
guessPriority() {
|
|
let query = `/api/Routes/${this.$stateParams.id}/guessPriority/`;
|
|
this.$http.get(query).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Order changed'));
|
|
this.$.model.refresh();
|
|
});
|
|
}
|
|
|
|
showTicketDescriptor(event, ticketFk) {
|
|
this.$.ticketDescriptor.ticketFk = ticketFk;
|
|
this.$.ticketDescriptor.parent = event.target;
|
|
this.$.ticketDescriptor.show();
|
|
event.preventDefault();
|
|
}
|
|
|
|
showClientDescriptor(event, clientFk) {
|
|
this.$.clientDescriptor.clientFk = clientFk;
|
|
this.$.clientDescriptor.parent = event.target;
|
|
this.$.clientDescriptor.show();
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$stateParams', '$scope', '$translate', '$http', 'vnApp'];
|
|
|
|
ngModule.component('vnRouteTickets', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|