fix bug with manual saving english translation

This commit is contained in:
Mateo Körber Belmonte
2025-03-25 12:13:44 +01:00
parent 88509d7b19
commit c5c4ea17a1
+23 -25
View File
@@ -701,35 +701,33 @@ function displayTranslation(translationText, originalDishes = []) {
saveBtn.style.borderRadius = '4px'; saveBtn.style.borderRadius = '4px';
saveBtn.style.cursor = 'pointer'; saveBtn.style.cursor = 'pointer';
saveBtn.onclick = async () => { saveBtn.onclick = async () => {
// Get all translated texts from form fields using the same logic as the PDF button // Get all translated texts from form fields
const updatedTranslations = []; const updatedTranslations = [];
const inputs = form.querySelectorAll('input:not([type="hidden"])'); const dishContainers = form.querySelectorAll('.dish-container');
const hiddenInputs = form.querySelectorAll('input[type="hidden"]');
let hiddenIndex = 0;
for (let i = 0; i < inputs.length; i++) { // Process each dish container separately
const mainCourse = inputs[i].value; dishContainers.forEach(container => {
let sideDish = ''; const inputs = container.querySelectorAll('input');
const hasHiddenInput = container.querySelector('input[type="hidden"]') !== null;
// If this is a soup (has hidden input), use empty side dish // This is a soup item (with hidden input)
if (hiddenInputs[hiddenIndex] && if (hasHiddenInput) {
hiddenInputs[hiddenIndex].parentNode === inputs[i].parentNode) { const mainCourse = inputs[0].value; // First input is main course (soup)
sideDish = ''; updatedTranslations.push({
hiddenIndex++; main_course: mainCourse,
i++; // Skip the next input which would be the hidden one side_dish: '' // Soups have no side dish
} else { });
// Otherwise get the next input as side dish
i++;
if (i < inputs.length) {
sideDish = inputs[i].value;
}
} }
// This is a regular dish
updatedTranslations.push({ else {
main_course: mainCourse, const mainCourse = inputs[0].value;
side_dish: sideDish const sideDish = inputs[1].value;
}); updatedTranslations.push({
} main_course: mainCourse,
side_dish: sideDish
});
}
});
// Save the translations to the database // Save the translations to the database
const saveResult = await saveTranslationsToDatabase(updatedTranslations, originalDishes); const saveResult = await saveTranslationsToDatabase(updatedTranslations, originalDishes);