add: wiederholungen
This commit is contained in:
parent
492b47a927
commit
e959c83a0d
@ -61,6 +61,15 @@
|
|||||||
<input type="time" class="form-control" id="calendarTime">
|
<input type="time" class="form-control" id="calendarTime">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if admin_enabled %}
|
||||||
|
<div class="row g-3 mt-1" id="calendarRecurrenceRow">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="calendarRepeatCount" class="form-label">Wöchentliche Wiederholung</label>
|
||||||
|
<input type="number" class="form-control" id="calendarRepeatCount" min="1" max="52" step="1" value="1">
|
||||||
|
<div class="form-text">Legt einzelne wöchentliche Termine an (für Nachbearbeitung).</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<label for="calendarTitle" class="form-label">Titel</label>
|
<label for="calendarTitle" class="form-label">Titel</label>
|
||||||
<input type="text" class="form-control" id="calendarTitle" required>
|
<input type="text" class="form-control" id="calendarTitle" required>
|
||||||
@ -435,6 +444,22 @@
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createRecurringEntries(entry, repeatCount) {
|
||||||
|
const count = Math.max(1, Math.min(52, repeatCount || 1));
|
||||||
|
const baseDate = entry.date;
|
||||||
|
if (!baseDate) return [];
|
||||||
|
const base = new Date(baseDate);
|
||||||
|
const savedEntries = [];
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const next = new Date(base);
|
||||||
|
next.setDate(base.getDate() + i * 7);
|
||||||
|
const entryForWeek = { ...entry, date: toLocalISO(next) };
|
||||||
|
const saved = await saveCalendarEntry(entryForWeek);
|
||||||
|
savedEntries.push(saved);
|
||||||
|
}
|
||||||
|
return savedEntries;
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteCalendarEntry(id) {
|
async function deleteCalendarEntry(id) {
|
||||||
const response = await fetch(`/api/calendar/${id}`, { method: 'DELETE' });
|
const response = await fetch(`/api/calendar/${id}`, { method: 'DELETE' });
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@ -490,12 +515,22 @@
|
|||||||
const form = document.getElementById('calendarForm');
|
const form = document.getElementById('calendarForm');
|
||||||
const daysContainer = document.getElementById('calendar-days');
|
const daysContainer = document.getElementById('calendar-days');
|
||||||
const locationFilter = document.getElementById('calendar-location-filter');
|
const locationFilter = document.getElementById('calendar-location-filter');
|
||||||
|
const repeatCountInput = document.getElementById('calendarRepeatCount');
|
||||||
|
const recurrenceRow = document.getElementById('calendarRecurrenceRow');
|
||||||
const calendarModal = modalEl && window.bootstrap ? new bootstrap.Modal(modalEl) : null;
|
const calendarModal = modalEl && window.bootstrap ? new bootstrap.Modal(modalEl) : null;
|
||||||
if (calendarModal) {
|
if (calendarModal) {
|
||||||
window.calendarModal = calendarModal;
|
window.calendarModal = calendarModal;
|
||||||
}
|
}
|
||||||
let calendarHasLoaded = false;
|
let calendarHasLoaded = false;
|
||||||
|
|
||||||
|
const setRecurrenceMode = (isEditing) => {
|
||||||
|
if (!recurrenceRow) return;
|
||||||
|
recurrenceRow.style.display = isEditing ? 'none' : '';
|
||||||
|
if (!isEditing && repeatCountInput) {
|
||||||
|
repeatCountInput.value = '1';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (addBtn && calendarModal) {
|
if (addBtn && calendarModal) {
|
||||||
addBtn.addEventListener('click', () => {
|
addBtn.addEventListener('click', () => {
|
||||||
if (form) form.reset();
|
if (form) form.reset();
|
||||||
@ -507,6 +542,7 @@
|
|||||||
const idInput = document.getElementById('calendarEntryId');
|
const idInput = document.getElementById('calendarEntryId');
|
||||||
if (idInput) idInput.value = '';
|
if (idInput) idInput.value = '';
|
||||||
|
|
||||||
|
setRecurrenceMode(false);
|
||||||
calendarModal.show();
|
calendarModal.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -523,14 +559,24 @@
|
|||||||
location: document.getElementById('calendarLocation')?.value,
|
location: document.getElementById('calendarLocation')?.value,
|
||||||
details: document.getElementById('calendarDetails')?.value
|
details: document.getElementById('calendarDetails')?.value
|
||||||
};
|
};
|
||||||
|
const isEditing = Boolean(entry.id);
|
||||||
|
const repeatCount = (!isEditing && window._calendarIsAdmin && repeatCountInput)
|
||||||
|
? Math.max(1, Math.min(52, parseInt(repeatCountInput.value, 10) || 1))
|
||||||
|
: 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (entry.id) {
|
if (isEditing) {
|
||||||
removeCalendarEntryFromUI(entry.id);
|
removeCalendarEntryFromUI(entry.id);
|
||||||
|
const saved = await saveCalendarEntry(entry);
|
||||||
|
addLocationOption(saved.location);
|
||||||
|
addCalendarEntry(saved);
|
||||||
|
} else {
|
||||||
|
const savedEntries = await createRecurringEntries(entry, repeatCount);
|
||||||
|
savedEntries.forEach(saved => {
|
||||||
|
addLocationOption(saved.location);
|
||||||
|
addCalendarEntry(saved);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const saved = await saveCalendarEntry(entry);
|
|
||||||
addLocationOption(saved.location);
|
|
||||||
addCalendarEntry(saved);
|
|
||||||
calendarModal.hide();
|
calendarModal.hide();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -603,6 +649,7 @@
|
|||||||
document.getElementById('calendarTitle').value = entry.title || '';
|
document.getElementById('calendarTitle').value = entry.title || '';
|
||||||
document.getElementById('calendarLocation').value = entry.location || '';
|
document.getElementById('calendarLocation').value = entry.location || '';
|
||||||
document.getElementById('calendarDetails').value = entry.details || '';
|
document.getElementById('calendarDetails').value = entry.details || '';
|
||||||
|
setRecurrenceMode(true);
|
||||||
if (calendarModal) calendarModal.show();
|
if (calendarModal) calendarModal.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user