diff --git a/public/i18n/de.json b/public/i18n/de.json index 62d3f5e..a8b12d9 100644 --- a/public/i18n/de.json +++ b/public/i18n/de.json @@ -22,6 +22,8 @@ "source-code": "Quellcode", "give-feedback": "Feedback geben", "feedback": "Feedback", + "sus-title": "Bewerte den Rechner", + "submit": "Absenden", "failed-base-area": "Die Mindestgrundfläche des Käfigs muss {{ MINIMUM_BASE_AREA }}m² (also z.B. 100x50cm) betragen.", "failed-overall-area": "Die Gesamtfläche im Käfig ist zu klein.", "failed-fall-height": "Die mögliche Fallhöhe darf nicht mehr als {{ maximum_fall_height }}cm betragen.", diff --git a/public/i18n/en.json b/public/i18n/en.json index 0236e7e..79b8314 100644 --- a/public/i18n/en.json +++ b/public/i18n/en.json @@ -22,6 +22,8 @@ "source-code": "Source Code", "give-feedback": "Give Feedback", "feedback": "Feedback", + "sus-title": "Rate the calculator", + "submit": "Submit", "failed-base-area": "The base area of the cage must not be below {{ MINIMUM_BASE_AREA }}m².", "failed-overall-area": "The overall area in the cage is to small.", "failed-fall-height": "The possible fall height between floors must not be above {{ maximum_fall_height }}cm.", diff --git a/public/index.html b/public/index.html index c814997..ec7ccbb 100644 --- a/public/index.html +++ b/public/index.html @@ -261,7 +261,8 @@
- Wir freuen uns sehr, wenn du uns Feedback zu unserem Rattenrechner gibst! - Der einfachste Weg das zu tun ist per E-Mail an webmaster@vdrd.de. -
-- Der Code dieser Website ist öffentlich einsehbar. - Gerne kannst du auch direkt dort einen Issue eröffnen! -
++ Wir freuen uns sehr, wenn du uns Feedback zu unserem Rattenrechner gibst! + Der einfachste Weg das zu tun ist per E-Mail an webmaster@vdrd.de. +
++ Der Code dieser Website ist öffentlich + einsehbar. + Gerne kannst du auch direkt dort einen + Issue eröffnen! +
++ +
+ + `; + form.insertBefore(field, form.querySelector('#sus-control')); + }); + + freetextQuestions.forEach((key, index) => { + const field = document.createElement("div"); + field.classList.add("field"); + field.id = key; + field.innerHTML = ` + ++ +
+ ` + form.insertBefore(field, form.querySelector('#sus-control')); + }) + return form; +} + +window.addEventListener('DOMContentLoaded', () => { + let form = prepareQuestionnaire(); + form.addEventListener("submit", async (e) => { + e.preventDefault(); + + const formData = new FormData(form); + const jsonData = {}; + + for (let [key, value] of formData.entries()) { + console.log(key, value); + if (key.startsWith("sws-question")) { + jsonData[key] = parseInt(value, 10); + } else { + jsonData[key] = value; + } + + } + + try { + const response = await fetch("https://storandom.hyteck.de/submit", { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(jsonData) + }); + + const messageDiv = document.getElementById("response-message"); + + if (response.ok) { + messageDiv.className = "notification is-success"; + messageDiv.setAttribute("data-i18n", "submit-success"); + messageDiv.textContent = "Survey submitted successfully!"; + } else { + messageDiv.className = "notification is-danger"; + messageDiv.setAttribute("data-i18n", "submit-error"); + messageDiv.textContent = "There was an error submitting the survey."; + } + + messageDiv.classList.remove("is-hidden"); + + } catch (error) { + const messageDiv = document.getElementById("response-message"); + messageDiv.className = "notification is-danger"; + messageDiv.removeAttribute("data-i18n"); // For dynamic error message + messageDiv.textContent = "Network error: " + error.message; + messageDiv.classList.remove("is-hidden"); + } + }); +});