From 83937c14e26202e7c3ef40253055721d3e652648 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 13 Aug 2025 11:03:19 +0200 Subject: [PATCH] Refactor EventForm component for improved readability and maintainability --- src/components/EventForm.vue | 52 +++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/components/EventForm.vue b/src/components/EventForm.vue index 3b75da6..51a4082 100644 --- a/src/components/EventForm.vue +++ b/src/components/EventForm.vue @@ -21,12 +21,23 @@ + - + + + + + + + + +
Mehrere Daten mit Komma oder Zeilenumbruch trennen
+ @@ -84,7 +95,9 @@ - + + + @@ -147,6 +160,8 @@ export default { onHomepage: false, assignedImage: null, imageFilename: '', + bulkDates: '', + bulkDates: '', }; }, watch: { @@ -192,23 +207,35 @@ export default { formatTime, async saveEvent() { try { - const payload = { + const basePayload = { ...this.eventData, eventTypeId: this.selectedEventType ? this.selectedEventType.id : null, institution_id: this.selectedInstitution ? this.selectedInstitution.id : null, event_place_id: this.selectedEventPlace ? this.selectedEventPlace.id : null, - contactPersonIds: this.selectedContactPersons.map(person => person.id) + contactPersonIds: this.selectedContactPersons.map(person => person.id), + dayOfWeek: this.eventData.dayOfWeek ? this.eventData.dayOfWeek.value ?? -1 : -1, + relatedImage: this.assignedImage, + alsoOnHomepage: this.onHomepage ? 1 : 0 }; - payload.dayOfWeek = payload.dayOfWeek ? payload.dayOfWeek.value ?? -1 : -1; - payload.relatedImage = this.assignedImage; - payload.alsoOnHomepage = this.onHomepage ? 1 : 0; - let response; - if (this.eventData.id) { - response = await axios.put(`/events/${this.eventData.id}`, payload); + if (this.dateMode === 'bulk' && this.bulkDates) { + // Split by comma or newline, trim, filter valid dates + const dates = this.bulkDates.split(/,|\n/).map(d => d.trim()).filter(d => /^\d{4}-\d{2}-\d{2}$/.test(d)); + const results = []; + for (const date of dates) { + const payload = { ...basePayload, date }; + const response = await axios.post('/events', payload); + results.push(response.data); + } + this.$emit('saved', results); } else { - response = await axios.post('/events', payload); + let response; + if (this.eventData.id) { + response = await axios.put(`/events/${this.eventData.id}`, basePayload); + } else { + response = await axios.post('/events', basePayload); + } + this.$emit('saved', response.data); } - this.$emit('saved', response.data); } catch (error) { console.error('Failed to save event:', error); } @@ -293,5 +320,4 @@ button { max-height: 50px; object-fit: contain; } -