diff --git a/src/components/management/EditEvent.vue b/src/components/management/EditEvent.vue index 96a52d3..02504a2 100644 --- a/src/components/management/EditEvent.vue +++ b/src/components/management/EditEvent.vue @@ -75,10 +75,15 @@ - - - - +
+
Schichten
+
+ +
+
+
@@ -139,7 +144,7 @@ export default defineComponent({ }); const templates = computed(() => store.templates); - const template = ref(undefined); + const template = ref(); const event = ref(props.modelValue || emptyEvent(startDate.value)); const eventtypes = computed(() => store.eventTypes); const recurrent = ref(false); @@ -160,13 +165,29 @@ export default defineComponent({ } function fromTemplate(tpl: FG.Event) { + const today = new Date() template.value = tpl; - event.value = Object.assign({}, tpl); + + event.value = Object.assign({}, tpl, {id: undefined}); + // Adjust the start to match today + event.value.start = date.adjustDate(event.value.start,{ + date: today.getDate(), + month: today.getMonth() + 1, // js inconsitency between getDate (1-31) and getMonth (0-11) + year: today.getFullYear() + }) + // Use timestamp difference for faster adjustment + const diff = event.value.start.getTime() - tpl.start.getTime() + // Adjust end of event and all jobs + if (event.value.end) + event.value.end.setTime(event.value.end.getTime() + diff) + event.value.jobs.forEach(job => { + job.start.setTime(job.start.getTime() + diff) + if (job.end) + job.end.setTime(job.end.getTime() + diff) + }) } async function save(template = false) { - if (!event.value.is_template && template) event.value.id = NaN; - event.value.is_template = template; try { if (event.value?.id !== undefined) {