diff --git a/js/interact.js b/js/interact.js
index 0a9222c..2fffba3 100644
--- a/js/interact.js
+++ b/js/interact.js
@@ -1,4 +1,3 @@
-
/**
* Submits answers
*/
@@ -31,14 +30,38 @@ export function getJsonAnswers(window, db) {
export function postAnswers(ans) {
$("#progress").html(`Submitting answers...`);
// ans = {"test" : 1}
- $.post(window.config.exam_submit_url, JSON.stringify(ans)).done(
- (data) => {
- console.log(data)
+ $.post(window.config.exam_submit_url, JSON.stringify(ans)).done((data) => {
+ console.log(data);
if (data.success) {
- alert(`${data.question_count} answers sucessfully submitted.`);
+ if (data.question_count == window.number_of_questions) {
+ let ret = confirm(
+ `${data.question_count} answers sucessfully submitted. Click OK to finish the exam.`
+ );
+
+ if (ret) {
+ window.review = true;
+ window.saveSession();
+ if (config.exam_results_url != "") {
+ let url = config.exam_results_url;
+
+ if (window.cid != "") {
+ url = url + window.cid;
+ }
+ $("#options-link")
+ .empty()
+ .append(
+ `
Results and answers
`
+ );
+ }
+ $("#options-panel").show();
+ } else {
+ }
+ } else {
+ alert(`${data.question_count} answers sucessfully submitted.`);
+ }
} else {
alert(`Error submitting answers: ${data.error}`);
}
- });
+ });
// $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
-}
\ No newline at end of file
+}
diff --git a/js/main.js b/js/main.js
index 7bf5c09..6de5cbe 100644
--- a/js/main.js
+++ b/js/main.js
@@ -135,6 +135,15 @@ async function loadExamList(data) {
})
);
});
+ if (config.exam_results_url != "") {
+ let url = config.exam_results_url;
+
+ $("#options-link")
+ .empty()
+ .append(
+ `
Results and answers
`
+ );
+ }
$("#options-panel").show();
}
@@ -252,7 +261,13 @@ function setUpQuestions(load_previous) {
}
});
- window.question_order = helper.shuffleArray(window.question_order);
+ let randomise_order = true;
+ if (window.config.randomise_order != undefined) {
+ randomise_order = window.config.randomise_order;
+ }
+ if (randomise_order) {
+ window.question_order = helper.shuffleArray(window.question_order);
+ }
}
window.number_of_questions = Object.keys(window.questions).length;
window.review = false;
@@ -299,8 +314,8 @@ function setUpQuestions(load_previous) {
$("#start-dialog").addClass("no-close");
$("#start-dialog .exam-time").prop("disabled", "true");
- $("#exam-candidate-number").toggle();
- $(".packet-database-options").toggle();
+ $("#exam-candidate-number").show();
+ $(".packet-database-options").hide();
$("#start-dialog").modal({
closeExisting: false, // Close existing modals. Set this to false if you need to stack multiple modal instances.
escapeClose: false, // Allows the user to close the modal by pressing `ESC`
@@ -1716,13 +1731,12 @@ $("#start-exam-button").click(function (evt) {
$(".start-packet-button").click(function (evt) {
if (window.exam_mode) {
- if (!Number.isInteger(parseInt($("#candidate-number2").val()))) {
- alert("Please enter a valid candidate number.")
- return
- }
+ if (!Number.isInteger(parseInt($("#candidate-number2").val()))) {
+ alert("Please enter a valid candidate number.");
+ return;
+ }
}
-
if (window.timer != null) {
window.timer.stop();
}
@@ -1913,5 +1927,7 @@ function saveSession() {
});
}
+window.saveSession = saveSession;
+
// Register Key Event Listener
window.addEventListener("keydown", viewer.keydown_handler);