This commit is contained in:
@ -98,16 +98,104 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showPasswordPrompt() {
|
function makeTableEditable() {
|
||||||
document.getElementById('delete-row-button').style.display = 'none';
|
const table = document.getElementById('database-nutrition-table');
|
||||||
|
const rows = table.getElementsByTagName('tr');
|
||||||
|
for (let i = 1; i < rows.length; i++) {
|
||||||
|
const cells = rows[i].getElementsByTagName('td');
|
||||||
|
for (let j = 0; j < cells.length; j++) {
|
||||||
|
cells[j].contentEditable = "true";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectTableData() {
|
||||||
|
const table = document.getElementById('database-nutrition-table');
|
||||||
|
const rows = table.getElementsByTagName('tr');
|
||||||
|
let data = [];
|
||||||
|
for (let i = 1; i < rows.length; i++) {
|
||||||
|
const cells = rows[i].getElementsByTagName('td');
|
||||||
|
data.push({
|
||||||
|
food: cells[0].innerText,
|
||||||
|
kcal: cells[1].innerText,
|
||||||
|
ew: cells[2].innerText,
|
||||||
|
fett: cells[3].innerText,
|
||||||
|
kh: cells[4].innerText,
|
||||||
|
bst: cells[5].innerText,
|
||||||
|
ca: cells[6].innerText
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateNutritionData() {
|
||||||
|
const updatedData = collectTableData();
|
||||||
|
getBearerToken(token => {
|
||||||
|
fetch('/update_nutrition', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(updatedData)
|
||||||
|
}).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
alert('Daten erfolgreich aktualisiert');
|
||||||
|
} else {
|
||||||
|
console.error('Fehler beim Aktualisieren der Daten');
|
||||||
|
}
|
||||||
|
}).catch(error => console.error('Fehler:', error));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let currentAction = '';
|
||||||
|
|
||||||
|
function showPasswordPrompt(action) {
|
||||||
|
currentAction = action; // 'delete' oder 'edit'
|
||||||
document.getElementById('password-prompt').style.display = 'block';
|
document.getElementById('password-prompt').style.display = 'block';
|
||||||
|
document.getElementById('delete-row-button').style.display = action === 'edit' ? 'none' : 'block';
|
||||||
|
document.getElementById('edit-row-button').style.display = action === 'delete' ? 'none' : 'block';
|
||||||
|
if(action === 'edit') {
|
||||||
|
// Auswahl aufheben, falls der Bearbeiten-Button gedrückt wurde
|
||||||
|
document.querySelectorAll('#database-nutrition-table .selected').forEach(row => {
|
||||||
|
row.classList.remove('selected');
|
||||||
|
});
|
||||||
|
updateDeleteButtonState(); // Aktualisiert den Zustand des Löschen-Buttons basierend auf der aktuellen Auswahl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hidePasswordPrompt() {
|
function hidePasswordPrompt() {
|
||||||
document.getElementById('delete-row-button').style.display = 'block';
|
|
||||||
document.getElementById('password-prompt').style.display = 'none';
|
document.getElementById('password-prompt').style.display = 'none';
|
||||||
|
document.getElementById('delete-row-button').style.display = 'block';
|
||||||
|
document.getElementById('edit-row-button').style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function performActionIfPasswordCorrect() {
|
||||||
|
const password = document.getElementById('password-input').value;
|
||||||
|
if (password === 'geheim') {
|
||||||
|
if(currentAction === 'delete') {
|
||||||
|
deleteSelectedRows(); // Funktion, die die ausgewählten Zeilen löscht
|
||||||
|
} else if(currentAction === 'edit') {
|
||||||
|
// Logik zum Bearbeiten der Einträge hier einfügen
|
||||||
|
}
|
||||||
|
hidePasswordPrompt();
|
||||||
|
} else {
|
||||||
|
alert('Falsches Passwort!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// function showPasswordPrompt() {
|
||||||
|
// document.getElementById('delete-row-button').style.display = 'none';
|
||||||
|
// document.getElementById('password-prompt').style.display = 'block';
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function hidePasswordPrompt() {
|
||||||
|
// document.getElementById('delete-row-button').style.display = 'block';
|
||||||
|
// document.getElementById('password-prompt').style.display = 'none';
|
||||||
|
// }
|
||||||
|
|
||||||
function deleteRowsIfPasswordCorrect() {
|
function deleteRowsIfPasswordCorrect() {
|
||||||
const password = document.getElementById('password-input').value;
|
const password = document.getElementById('password-input').value;
|
||||||
if (password === 'geheim') {
|
if (password === 'geheim') {
|
||||||
@ -236,11 +324,12 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<button id="delete-row-button" onclick="showPasswordPrompt()">Zeilen löschen</button>
|
<button id="delete-row-button" onclick="showPasswordPrompt('delete')">Zeilen löschen</button>
|
||||||
|
<button id="edit-row-button" onclick="showPasswordPrompt('edit')">Bearbeiten</button>
|
||||||
|
|
||||||
<div id="password-prompt" style="display: none;">
|
<div id="password-prompt" style="display: none;">
|
||||||
<input type="password" id="password-input" placeholder="Passwort">
|
<input type="password" id="password-input" placeholder="Passwort">
|
||||||
<button id="ok-button" onclick="deleteRowsIfPasswordCorrect()">OK</button>
|
<button id="ok-button" onclick="performActionIfPasswordCorrect()">OK</button>
|
||||||
<button id="cancel-button" onclick="hidePasswordPrompt()">Abbrechen</button>
|
<button id="cancel-button" onclick="hidePasswordPrompt()">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user