import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { getScopeDates(days) { const today = new Date(); today.setHours(0, 0, 0, 0); const daysOnward = new Date(today); daysOnward.setDate(today.getDate() + days); daysOnward.setHours(23, 59, 59, 999); return {shippedFrom: today, shippedTo: daysOnward}; } onSearch(params) { if (params) { let newParams = params; if (params.scopeDays) { const scopeDates = this.getScopeDates(params.scopeDays); Object.assign(newParams, scopeDates); } else if (Object.entries(params).length == 0) newParams = this.getScopeDates(1); this.$.model.applyFilter(null, newParams); } else this.$.model.clear(); } stopEvent(event) { event.preventDefault(); event.stopImmediatePropagation(); } cloneTravel(event, travel) { this.stopEvent(event); this.travelSelected = travel; this.$.clone.show(); } onCloneAccept(response) { if (!(response == 'accept' && this.travelSelected)) return; if (this.travelSelected) { const travel = { ref: this.travelSelected.ref, agencyModeFk: this.travelSelected.agencyFk, shipped: this.travelSelected.shipped, landed: this.travelSelected.landed, warehouseInFk: this.travelSelected.warehouseInFk, warehouseOutFk: this.travelSelected.warehouseOutFk }; const queryParams = JSON.stringify(travel); this.$state.go('travel.create', {q: queryParams}); } this.travelSelected = null; } preview(event, travel) { this.stopEvent(event); this.travelSelected = travel; this.$.summary.show(); } } ngModule.component('vnTravelIndex', { template: require('./index.html'), controller: Controller });