salix/modules/travel/front/extra-community/index.js

106 lines
2.9 KiB
JavaScript
Raw Normal View History

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));
this.draggableElement = 'a[draggable]';
2021-01-19 12:06:10 +00:00
this.droppableElement = 'vn-tbody[vn-droppable]';
2020-11-20 14:05:57 +00:00
const scopeDays = 14;
const landedFrom = new Date();
landedFrom.setHours(0, 0, 0, 0);
const landedTo = new Date();
landedTo.setDate(landedTo.getDate() + scopeDays);
landedTo.setHours(23, 59, 59, 59);
this.defaultFilter = {
landedFrom: landedFrom,
landedTo: landedTo,
continent: 'AM'
};
}
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;
}
dragEnd($event) {
const draggable = this.findDraggable($event);
draggable.classList.remove('dragging');
this.entryId = null;
this.entry = null;
}
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!')));
}
}
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;
return Object.assign({
authorization: this.vnToken.token
}, userParams);
}
showReport() {
this.vnReport.show('extra-community', this.reportParams);
}
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
});