add loadWeekData

This commit is contained in:
Mateo Körber Belmonte
2025-02-15 19:49:30 +01:00
parent 9ea4c33298
commit 74d26abd4b
2 changed files with 86 additions and 20 deletions
+70 -16
View File
@@ -145,7 +145,8 @@
<div id="dayForm0" class="day-form active">
<input type="text" class="input-field-14" name="dateTitle0" style="bottom: 68%; left: 13.4%"
placeholder="Datum">
<input type="checkbox" class="input-field-13" name="halal0" style="bottom: 62.2%; left: 22.1%">
<input type="checkbox" class="input-field-13" name="halal0"
style="bottom: 62.2%; left: 22.1%">
<input type="text" class="input-field-12" name="meatMain0" style="bottom: 55%; left: 14%"
placeholder="Fleischgericht">
<input type="text" class="input-field-12" name="meatSide0" style="bottom: 50.2%; left: 14%"
@@ -156,13 +157,14 @@
placeholder="Veggie">
<input type="text" class="input-field-12" name="veggiSide0" style="bottom: 20.8%; left: 14%"
placeholder="Beilage">
<input type="text" class="input-field-10" name="veggiPrice0" style="bottom: 15.5%; left: 14%"
placeholder="Preis">
<input type="text" class="input-field-10" name="veggiPrice0"
style="bottom: 15.5%; left: 14%" placeholder="Preis">
</div>
<div id="dayForm1" class="day-form">
<input type="text" class="input-field-14" name="dateTitle1" style="bottom: 68%; left: 13.4%"
placeholder="Datum">
<input type="checkbox" class="input-field-13" name="halal1" style="bottom: 62.2%; left: 22.1%">
<input type="checkbox" class="input-field-13" name="halal1"
style="bottom: 62.2%; left: 22.1%">
<input type="text" class="input-field-12" name="meatMain1" style="bottom: 55%; left: 14%"
placeholder="Fleischgericht">
<input type="text" class="input-field-12" name="meatSide1" style="bottom: 50.2%; left: 14%"
@@ -173,13 +175,14 @@
placeholder="Veggie">
<input type="text" class="input-field-12" name="veggiSide1" style="bottom: 20.8%; left: 14%"
placeholder="Beilage">
<input type="text" class="input-field-10" name="veggiPrice1" style="bottom: 15.5%; left: 14%"
placeholder="Preis">
<input type="text" class="input-field-10" name="veggiPrice1"
style="bottom: 15.5%; left: 14%" placeholder="Preis">
</div>
<div id="dayForm2" class="day-form">
<input type="text" class="input-field-14" name="dateTitle2" style="bottom: 68%; left: 13.4%"
placeholder="Datum">
<input type="checkbox" class="input-field-13" name="halal2" style="bottom: 62.2%; left: 22.1%">
<input type="checkbox" class="input-field-13" name="halal2"
style="bottom: 62.2%; left: 22.1%">
<input type="text" class="input-field-12" name="meatMain2" style="bottom: 55%; left: 14%"
placeholder="Fleischgericht">
<input type="text" class="input-field-12" name="meatSide2" style="bottom: 50.2%; left: 14%"
@@ -190,13 +193,14 @@
placeholder="Veggie">
<input type="text" class="input-field-12" name="veggiSide2" style="bottom: 20.8%; left: 14%"
placeholder="Beilage">
<input type="text" class="input-field-10" name="veggiPrice2" style="bottom: 15.5%; left: 14%"
placeholder="Preis">
<input type="text" class="input-field-10" name="veggiPrice2"
style="bottom: 15.5%; left: 14%" placeholder="Preis">
</div>
<div id="dayForm3" class="day-form">
<input type="text" class="input-field-14" name="dateTitle3" style="bottom: 68%; left: 13.4%"
placeholder="Datum">
<input type="checkbox" class="input-field-13" name="halal3" style="bottom: 62.2%; left: 22.1%">
<input type="checkbox" class="input-field-13" name="halal3"
style="bottom: 62.2%; left: 22.1%">
<input type="text" class="input-field-12" name="meatMain3" style="bottom: 55%; left: 14%"
placeholder="Fleischgericht">
<input type="text" class="input-field-12" name="meatSide3" style="bottom: 50.2%; left: 14%"
@@ -207,13 +211,14 @@
placeholder="Veggie">
<input type="text" class="input-field-12" name="veggiSide3" style="bottom: 20.8%; left: 14%"
placeholder="Beilage">
<input type="text" class="input-field-10" name="veggiPrice3" style="bottom: 15.5%; left: 14%"
placeholder="Preis">
<input type="text" class="input-field-10" name="veggiPrice3"
style="bottom: 15.5%; left: 14%" placeholder="Preis">
</div>
<div id="dayForm4" class="day-form">
<input type="text" class="input-field-14" name="dateTitle4" style="bottom: 68%; left: 13.4%"
placeholder="Datum">
<input type="checkbox" class="input-field-13" name="halal4" style="bottom: 62.2%; left: 22.1%">
<input type="checkbox" class="input-field-13" name="halal4"
style="bottom: 62.2%; left: 22.1%">
<input type="text" class="input-field-12" name="meatMain4" style="bottom: 55%; left: 14%"
placeholder="Fleischgericht">
<input type="text" class="input-field-12" name="meatSide4" style="bottom: 50.2%; left: 14%"
@@ -224,8 +229,8 @@
placeholder="Veggie">
<input type="text" class="input-field-12" name="veggiSide4" style="bottom: 20.8%; left: 14%"
placeholder="Beilage">
<input type="text" class="input-field-10" name="veggiPrice4" style="bottom: 15.5%; left: 14%"
placeholder="Preis">
<input type="text" class="input-field-10" name="veggiPrice4"
style="bottom: 15.5%; left: 14%" placeholder="Preis">
</div>
</form>
</div>
@@ -313,6 +318,10 @@
currentDayIndex = 0; // Reset to Monday
updateWeekDisplay();
updateDayDisplay();
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber} ${year}`;
loadWeekData(week);
}
function nextWeek() {
@@ -320,10 +329,16 @@
currentDayIndex = 0; // Reset to Monday
updateWeekDisplay();
updateDayDisplay();
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber} ${year}`;
loadWeekData(week);
}
function saveWeek() {
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber} ${year}`;
const entries = [];
for (let i = 0; i < 5; i++) {
@@ -351,7 +366,7 @@
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ weekNumber, entries })
body: JSON.stringify({ week, entries })
})
.then(response => response.json())
.then(data => {
@@ -363,9 +378,48 @@
});
}
function loadWeekData(week) {
fetch(`/load-week?week=${encodeURIComponent(week)}`)
.then(response => response.json())
.then(data => {
// Clear all input fields
for (let i = 0; i < 5; i++) {
document.querySelector(`input[name="dateTitle${i}"]`).value = '';
document.querySelector(`input[name="meatMain${i}"]`).value = '';
document.querySelector(`input[name="meatSide${i}"]`).value = '';
document.querySelector(`input[name="halal${i}"]`).checked = false;
document.querySelector(`input[name="meatPrice${i}"]`).value = '';
document.querySelector(`input[name="veggiMain${i}"]`).value = '';
document.querySelector(`input[name="veggiSide${i}"]`).value = '';
document.querySelector(`input[name="veggiPrice${i}"]`).value = '';
}
// Fill input fields with loaded data
data.forEach(entry => {
const dayIndex = entry.day_index;
document.querySelector(`input[name="dateTitle${dayIndex}"]`).value = entry.date_title;
document.querySelector(`input[name="meatMain${dayIndex}"]`).value = entry.meat_main;
document.querySelector(`input[name="meatSide${dayIndex}"]`).value = entry.meat_side;
document.querySelector(`input[name="halal${dayIndex}"]`).checked = entry.halal === 1;
document.querySelector(`input[name="meatPrice${dayIndex}"]`).value = entry.meat_price;
document.querySelector(`input[name="veggiMain${dayIndex}"]`).value = entry.veggi_main;
document.querySelector(`input[name="veggiSide${dayIndex}"]`).value = entry.veggi_side;
document.querySelector(`input[name="veggiPrice${dayIndex}"]`).value = entry.veggi_price;
});
})
.catch(error => {
console.error('Error loading week:', error);
alert('Fehler beim Laden der Woche');
});
}
// Initialize the display when page loads
updateWeekDisplay();
updateDayDisplay();
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber} ${year}`;
loadWeekData(week);
</script>
</body>