diff --git a/lms/templates/quiz.html b/lms/templates/quiz.html index 8ac0abbd..093bceda 100644 --- a/lms/templates/quiz.html +++ b/lms/templates/quiz.html @@ -1,23 +1,25 @@ {% if attempts_exceeded %}
-
{{ quiz.title }}
+
{{ quiz.title }}
{{ _("You have already exceeded the maximum number of attempts allowed for this quiz.") }}
{{ _("You latest score is {0}.").format(last_attempt_score) }}
{% else %} -
{{ quiz.title }}
+
{{ quiz.title }}
{{ quiz.title }}
- {{ _("This quiz has {0} questions.").format(quiz.questions | length) }} + {{ _("There are {0} questions in this quiz.").format(quiz.questions | length) }} + {% if quiz.max_attempts %} {% set suffix = "times" if quiz.max_attempts > 1 else "time" %} - {{ _("You can attempt this quiz {0} {1}.").format(quiz.max_attempts, suffix) }} + {{ _("This quiz can only be taken {0} {1}. If you attempt the quiz and leave the page before submitting, the quiz will be automatically submitted.").format(quiz.max_attempts, suffix) }} {% endif %} + {% if quiz.time %} - {{ _("The quiz is time bound. You will have {0} seconds per question.").format(quiz.time) }} + {{ _("The quiz has a time limit. Each question will be given {0} seconds.").format(quiz.time) }} {% endif %}
diff --git a/lms/www/batch/learn.js b/lms/www/batch/learn.js index 131aacb7..21089e50 100644 --- a/lms/www/batch/learn.js +++ b/lms/www/batch/learn.js @@ -49,8 +49,16 @@ frappe.ready(() => { $("#start-banner").addClass("hide"); $("#quiz-form").removeClass("hide"); mark_active_question(); - }) + }); + if ($("#quiz-form").length) { + window.addEventListener("beforeunload", (e) => { + e.preventDefault(); + if ($("#quiz-title").data("max-attempts") && $(".active-question").length) + quiz_summary(); + e.returnValue = ''; + }); + } }); const save_current_lesson = () => { @@ -158,27 +166,27 @@ const move_to_next_lesson = (status, e) => { } }; -const quiz_summary = (e) => { - e.preventDefault(); - var quiz_name = $("#quiz-title").text(); - var total_questions = $(".question").length; +const quiz_summary = (e=undefined) => { + e && e.preventDefault(); + var quiz_name = $("#quiz-title").text(); + var total_questions = $(".question").length; - frappe.call({ - method: "lms.lms.doctype.lms_quiz.lms_quiz.quiz_summary", - args: { - "quiz": quiz_name, - "results": localStorage.getItem(quiz_name) - }, - callback: (data) => { - var message = data.message == total_questions ? "Excellent Work" : "You were almost there." - $(".question").addClass("hide"); - $("#summary").addClass("hide"); - $("#quiz-form").parent().prepend( - `

${message} 👏

-
${data.message}/${total_questions} correct.
`); - $("#try-again").removeClass("hide"); - } - }) + frappe.call({ + method: "lms.lms.doctype.lms_quiz.lms_quiz.quiz_summary", + args: { + "quiz": quiz_name, + "results": localStorage.getItem(quiz_name) + }, + callback: (data) => { + var message = data.message == total_questions ? "Excellent Work" : "You were almost there." + $(".question").addClass("hide"); + $("#summary").addClass("hide"); + $("#quiz-form").parent().prepend( + `

${message} 👏

+
${data.message}/${total_questions} correct.
`); + $("#try-again").removeClass("hide"); + } + }) }; const try_quiz_again = (e) => {