diff --git a/app/static/js/nopaque.js b/app/static/js/nopaque.js index bde7cb62..89afcea0 100644 --- a/app/static/js/nopaque.js +++ b/app/static/js/nopaque.js @@ -16,6 +16,29 @@ nopaque["foreignJobsSubscribers"] = []; // nopaque functions +nopaque["forms"] = {}; +nopaque["forms"]["init"] = function() { + for (let form of document.querySelectorAll(".nopaque-form")) { + form.addEventListener("submit", function(event) { + event.preventDefault(); + if (form.dataset.hasOwnProperty('loadingModal')) { + let loadingModalElement = document.getElementById(form.dataset.loadingModal); + M.Modal.getInstance(loadingModalElement).open(); + } + let data = {}; + for (let input of form.querySelectorAll("input")) { + if (input.type === "file") { + file = input.files[0]; + data[`${input.name}-wrapper`] = {"bytes": file, "name": file.name}; + } else { + data[input.name] = input.value; + } + } + nopaque.socket.emit(`submit-${form.id}`, data); + }); + } +} + nopaque["navigation"] = {}; nopaque["navigation"]["init"] = function() { for (let entry of document.querySelectorAll("#slide-out a:not(.subheader)")) { @@ -112,6 +135,7 @@ document.addEventListener("DOMContentLoaded", function() { {"alignment": "right", "constrainWidth": false, "coverTrigger": false}); M.Dropdown.init(document.getElementById("nav-account"), {"alignment": "right", "constrainWidth": false, "coverTrigger": false}); + nopaque.forms.init(); nopaque.navigation.init(); nopaque.socket.emit("subscribe_user_ressources"); }); diff --git a/app/templates/base.html.j2 b/app/templates/base.html.j2 index dd0f2fa9..3ee78076 100644 --- a/app/templates/base.html.j2 +++ b/app/templates/base.html.j2 @@ -105,7 +105,7 @@ DarkReader.enable({"brightness": 100, "contrast": 100, "sepia": 0}); {% endif %} {% for flashed_message in get_flashed_messages() %} - toast("{{ flashed_message }}"); + nopaque.toast("{{ flashed_message }}"); {% endfor %} }); diff --git a/app/templates/test/index.html.j2 b/app/templates/test/index.html.j2 index f0ec41f1..3fb77913 100644 --- a/app/templates/test/index.html.j2 +++ b/app/templates/test/index.html.j2 @@ -7,7 +7,7 @@