2020-11-11 11:34:07 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
import './style.scss';
|
|
|
|
|
2020-11-20 14:05:57 +00:00
|
|
|
class Controller extends Section {
|
2021-01-18 07:33:20 +00:00
|
|
|
constructor($element, $, vnReport) {
|
2020-11-20 14:05:57 +00:00
|
|
|
super($element, $);
|
|
|
|
|
2021-01-18 07:33:20 +00:00
|
|
|
this.vnReport = vnReport;
|
|
|
|
|
2020-11-20 14:05:57 +00:00
|
|
|
const draggable = this.element.querySelector('.travel-list');
|
|
|
|
draggable.addEventListener('dragstart',
|
|
|
|
event => this.dragStart(event));
|
|
|
|
draggable.addEventListener('dragend',
|
|
|
|
event => this.dragEnd(event));
|
|
|
|
|
2022-09-13 13:11:14 +00:00
|
|
|
draggable.addEventListener('dragover',
|
|
|
|
event => this.dragOver(event));
|
|
|
|
draggable.addEventListener('dragenter',
|
|
|
|
event => this.dragEnter(event));
|
|
|
|
draggable.addEventListener('dragleave',
|
|
|
|
event => this.dragLeave(event));
|
|
|
|
|
|
|
|
this.draggableElement = 'tr[draggable]';
|
|
|
|
this.droppableElement = 'tbody[vn-droppable]';
|
2020-11-20 14:05:57 +00:00
|
|
|
|
2022-03-29 08:17:26 +00:00
|
|
|
const twoDays = 2;
|
2023-01-16 14:18:24 +00:00
|
|
|
const shippedFrom = Date.vnNew();
|
2022-03-29 08:17:26 +00:00
|
|
|
shippedFrom.setDate(shippedFrom.getDate() - twoDays);
|
2022-03-28 11:24:26 +00:00
|
|
|
shippedFrom.setHours(0, 0, 0, 0);
|
2020-11-20 14:05:57 +00:00
|
|
|
|
2022-03-28 11:24:26 +00:00
|
|
|
const sevenDays = 7;
|
2023-01-16 14:18:24 +00:00
|
|
|
const landedTo = Date.vnNew();
|
2022-03-28 11:24:26 +00:00
|
|
|
landedTo.setDate(landedTo.getDate() + sevenDays);
|
2020-11-20 14:05:57 +00:00
|
|
|
landedTo.setHours(23, 59, 59, 59);
|
|
|
|
|
|
|
|
this.defaultFilter = {
|
2022-03-28 11:24:26 +00:00
|
|
|
shippedFrom: shippedFrom,
|
2020-11-20 14:05:57 +00:00
|
|
|
landedTo: landedTo,
|
|
|
|
continent: 'AM'
|
|
|
|
};
|
2022-09-13 13:11:14 +00:00
|
|
|
|
|
|
|
this.smartTableOptions = {};
|
2020-11-20 14:05:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 13:11:14 +00:00
|
|
|
onDragInterval() {
|
|
|
|
if (this.dragClientY > 0 && this.dragClientY < 75)
|
|
|
|
this.$window.scrollTo(0, this.$window.scrollY - 10);
|
|
|
|
|
|
|
|
const maxHeight = window.screen.availHeight - (window.outerHeight - window.innerHeight);
|
|
|
|
if (this.dragClientY > maxHeight - 75 && this.dragClientY < maxHeight)
|
|
|
|
this.$window.scrollTo(0, this.$window.scrollY + 10);
|
|
|
|
}
|
|
|
|
|
2020-11-20 14:05:57 +00:00
|
|
|
findDraggable($event) {
|
|
|
|
const target = $event.target;
|
|
|
|
const draggable = target.closest(this.draggableElement);
|
|
|
|
|
|
|
|
return draggable;
|
|
|
|
}
|
|
|
|
|
|
|
|
findDroppable($event) {
|
|
|
|
const target = $event.target;
|
|
|
|
const droppable = target.closest(this.droppableElement);
|
|
|
|
|
|
|
|
return droppable;
|
|
|
|
}
|
|
|
|
|
|
|
|
dragStart($event) {
|
|
|
|
const draggable = this.findDraggable($event);
|
|
|
|
draggable.classList.add('dragging');
|
|
|
|
|
2020-11-23 07:12:33 +00:00
|
|
|
const id = parseInt(draggable.id);
|
2020-11-20 14:05:57 +00:00
|
|
|
this.entryId = id;
|
|
|
|
this.entry = draggable;
|
2022-09-13 13:11:14 +00:00
|
|
|
this.interval = setInterval(() => this.onDragInterval(), 50);
|
2020-11-20 14:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dragEnd($event) {
|
|
|
|
const draggable = this.findDraggable($event);
|
|
|
|
draggable.classList.remove('dragging');
|
|
|
|
this.entryId = null;
|
|
|
|
this.entry = null;
|
2022-09-13 13:11:14 +00:00
|
|
|
|
|
|
|
clearInterval(this.interval);
|
2020-11-20 14:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onDrop($event) {
|
|
|
|
const model = this.$.model;
|
|
|
|
const droppable = this.findDroppable($event);
|
2020-11-23 07:12:33 +00:00
|
|
|
const travelId = parseInt(droppable.id);
|
2020-11-20 14:05:57 +00:00
|
|
|
|
|
|
|
const currentDroppable = this.entry.closest(this.droppableElement);
|
|
|
|
|
|
|
|
if (currentDroppable == droppable) return;
|
|
|
|
|
|
|
|
if (this.entryId && travelId) {
|
|
|
|
const path = `Entries/${this.entryId}`;
|
|
|
|
this.$http.patch(path, {travelFk: travelId})
|
|
|
|
.then(() => model.refresh())
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 13:11:14 +00:00
|
|
|
undrop() {
|
|
|
|
if (!this.dropping) return;
|
|
|
|
this.dropping.classList.remove('dropping');
|
|
|
|
this.dropping = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
dragOver($event) {
|
|
|
|
this.dragClientY = $event.clientY;
|
|
|
|
$event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
dragEnter($event) {
|
|
|
|
let element = this.findDroppable($event);
|
|
|
|
if (element) this.dropCount++;
|
|
|
|
|
|
|
|
if (element != this.dropping) {
|
|
|
|
this.undrop();
|
|
|
|
if (element) element.classList.add('dropping');
|
|
|
|
this.dropping = element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dragLeave($event) {
|
|
|
|
let element = this.findDroppable($event);
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
this.dropCount--;
|
|
|
|
if (this.dropCount == 0) this.undrop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 13:21:17 +00:00
|
|
|
save(id, data) {
|
|
|
|
const endpoint = `Travels/${id}`;
|
|
|
|
this.$http.patch(endpoint, data)
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
|
|
|
}
|
2021-01-18 07:33:20 +00:00
|
|
|
|
|
|
|
get reportParams() {
|
|
|
|
const userParams = this.$.model.userParams;
|
2023-03-14 08:59:29 +00:00
|
|
|
const currentFilter = this.$.model.currentFilter;
|
|
|
|
|
2021-01-18 07:33:20 +00:00
|
|
|
return Object.assign({
|
2023-03-14 08:59:29 +00:00
|
|
|
authorization: this.vnToken.token,
|
|
|
|
filter: currentFilter
|
2021-01-18 07:33:20 +00:00
|
|
|
}, userParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
showReport() {
|
2022-09-26 11:33:27 +00:00
|
|
|
this.vnReport.show(`Travels/extra-community-pdf`, this.reportParams);
|
2021-01-18 07:33:20 +00:00
|
|
|
}
|
2020-11-20 14:05:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 07:33:20 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', 'vnReport'];
|
|
|
|
|
2020-11-11 11:34:07 +00:00
|
|
|
ngModule.vnComponent('vnTravelExtraCommunity', {
|
|
|
|
template: require('./index.html'),
|
2020-11-20 14:05:57 +00:00
|
|
|
controller: Controller
|
2020-11-11 11:34:07 +00:00
|
|
|
});
|