95 lines
3.9 KiB
HTML
95 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Neue Lebensmittel hinzufügen</title>
|
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
|
<link rel="shortcut icon" href="../static/images/favicon.ico">
|
|
|
|
<script>
|
|
function updateSubmitButtonState() {
|
|
const inputs = document.querySelectorAll('#nutrition-form input');
|
|
const allFilled = Array.from(inputs).every(input => input.value.trim() !== '');
|
|
document.getElementById('submit-button').disabled = !allFilled;
|
|
}
|
|
|
|
function getBearerToken(callback) {
|
|
fetch('/get_token')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
callback(data.token);
|
|
})
|
|
.catch(error => {
|
|
console.error('Fehler beim Abrufen des Tokens:', error);
|
|
});
|
|
}
|
|
|
|
function addNutritionEntry() {
|
|
|
|
const form = document.getElementById('nutrition-form');
|
|
const formData = new FormData(form);
|
|
|
|
fetch('/add_nutrition', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: formData
|
|
}).then(response => {
|
|
// Behandlung der Serverantwort
|
|
// Beispielsweise das Formular zurücksetzen
|
|
form.reset();
|
|
updateSubmitButtonState();
|
|
}).catch(error => {
|
|
console.error('Fehler:', error);
|
|
});
|
|
// ... Code, um den Eintrag zur Datenbank hinzuzufügen
|
|
|
|
// Nach dem Hinzufügen, setze alle Eingabefelder zurück
|
|
document.querySelectorAll('#nutrition-form input').forEach(input => {
|
|
input.value = ''; // Setzt den Wert jedes Eingabefeldes zurück
|
|
});
|
|
|
|
// Deaktiviere den "Hinzufügen"-Button wieder
|
|
document.getElementById('submit-button').disabled = true;
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<nav id="navbar">
|
|
<h1>Elo's Rezept Rechner</h1>
|
|
<ul>
|
|
<li><a href="/">Rechner</a></li>
|
|
<li><a href="/nutrition" class="active">Neue Lebensmittel</a></li>
|
|
</ul>
|
|
</nav>
|
|
|
|
<div class="content">
|
|
<form onsubmit="event.preventDefault(); addNutritionEntry();" method="POST" id="nutrition-form">
|
|
<table id="nutrition-input-table">
|
|
<tr>
|
|
<th>Lebensmittel</th>
|
|
<th>kcal</th>
|
|
<th>EW</th>
|
|
<th>Fett</th>
|
|
<th>KH</th>
|
|
<th>BST</th>
|
|
<th>CA</th>
|
|
</tr>
|
|
<tr>
|
|
<td><input type="text" name="food" placeholder="Lebensmittel" oninput="updateSubmitButtonState()"></td>
|
|
<td><input <input type="text" name="kcal" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
|
<td><input <input type="text" name="ew" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
|
<td><input <input type="text" name="fett" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
|
<td><input <input type="text" name="kh" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
|
<td><input <input type="text" name="bst" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
|
<td><input <input type="text" name="ca" pattern="\d+([.,]\d{1,2})?" placeholder="mg" oninput="updateSubmitButtonState()"></td>
|
|
</tr>
|
|
</table>
|
|
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|