From 58993cbf511379f8ef5e1157186e8852b60de8f6 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 5 Jul 2024 10:10:58 +0200 Subject: [PATCH] feat: enhance quiz submit handling and hide back buttons - Hide all buttons labeled 'Back' on document ready - Add session key and attempt values logging to assist debugging - Add AJAX request to finalize quiz attempts upon submission - Ensure proper navigation or modal closure after quiz submission These changes improve user experience by providing seamless form submission and debugging support. --- global.js | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/global.js b/global.js index 259a95f..54c5780 100644 --- a/global.js +++ b/global.js @@ -53,6 +53,8 @@ document.addEventListener("DOMContentLoaded", function () { .then(() => { console.log("Bootstrap loaded successfully"); $(document).ready(function () { + $(".btn-secondary:contains('Back')").hide() + var embedded = getUrlParameter("embed"); var inModal = getUrlParameter("modal"); @@ -94,18 +96,43 @@ document.addEventListener("DOMContentLoaded", function () { encodeURIComponent(submitButton.val()); } + var sesskey = form.find('input[name=sesskey]').val(); + var attempt = form.find('input[name=attempt]').val(); + + console.log(sesskey); + console.log(attempt); + // Perform the AJAX request $.ajax({ url: form.attr("action"), // Use the form's action attribute type: form.attr("method"), // Use the form's method attribute data: formData, success: function (response) { - // Close the modal if `modal=1` is set - if (inModal === "1") { - window.top.closeQuizModal(); + if (form.attr("action").includes("/quiz/")) { + var finalize = "/mod/quiz/processattempt.php"; + var data = { + attempt: attempt, + finishattempt: 1, + sesskey: sesskey, + }; + $.post(finalize, data, function (response) { + console.log(response); + // Close the modal if `modal=1` is set + if (inModal === "1") { + window.top.closeQuizModal(); + } else { + // Else call the nextContent function + window.top.nextContent(); + } + }); } else { - // Else call the nextContent function - window.top.nextContent(); + // Close the modal if `modal=1` is set + if (inModal === "1") { + window.top.closeQuizModal(); + } else { + // Else call the nextContent function + window.top.nextContent(); + } } }, error: function (xhr, status, error) {