start convert to events
This commit is contained in:
+10
-3
@@ -1,3 +1,4 @@
|
|||||||
|
import {exam_query_url} from "./config.js";
|
||||||
import * as helper from "./helpers.js";
|
import * as helper from "./helpers.js";
|
||||||
/**
|
/**
|
||||||
* Submits answers
|
* Submits answers
|
||||||
@@ -12,6 +13,7 @@ export function submitAnswers(exam_details, db, config) {
|
|||||||
postAnswers(json, config, exam_details);
|
postAnswers(json, config, exam_details);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
console.log(e)
|
||||||
alert("No answers to submit");
|
alert("No answers to submit");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -21,6 +23,12 @@ export function submitAnswers(exam_details, db, config) {
|
|||||||
* @return {JSON} - answers
|
* @return {JSON} - answers
|
||||||
*/
|
*/
|
||||||
export function getJsonAnswers(exam_details, db) {
|
export function getJsonAnswers(exam_details, db) {
|
||||||
|
console.log(exam_details)
|
||||||
|
console.log({
|
||||||
|
aid: exam_details.aid,
|
||||||
|
cid: exam_details.cid,
|
||||||
|
eid: exam_details.eid,
|
||||||
|
})
|
||||||
return db.answers
|
return db.answers
|
||||||
.where({
|
.where({
|
||||||
aid: exam_details.aid,
|
aid: exam_details.aid,
|
||||||
@@ -42,14 +50,13 @@ export function postAnswers(ans, config, exam_details) {
|
|||||||
console.log("returned data", data);
|
console.log("returned data", data);
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
$("#submit-error-overlay").remove();
|
$("#submit-error-overlay").remove();
|
||||||
if (data.question_count == window.number_of_questions) {
|
if (data.question_count == exam_details.number_of_questions) {
|
||||||
let ret = confirm(
|
let ret = confirm(
|
||||||
`${data.question_count} answers sucessfully submitted. Click OK to finish the exam.`
|
`${data.question_count} answers sucessfully submitted. Click OK to finish the exam.`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
window.review = true;
|
$( document ).trigger( "saveSessionEvent", [ true ] );
|
||||||
window.saveSession();
|
|
||||||
if (config.exam_results_url != "") {
|
if (config.exam_results_url != "") {
|
||||||
let url = config.exam_results_url;
|
let url = config.exam_results_url;
|
||||||
|
|
||||||
|
|||||||
+26
-19
@@ -15,6 +15,7 @@ let exam_details = {
|
|||||||
cid: "",
|
cid: "",
|
||||||
eid: 5678,
|
eid: 5678,
|
||||||
exam_mode: false,
|
exam_mode: false,
|
||||||
|
number_of_questions: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
//window.exam_mode = false;
|
//window.exam_mode = false;
|
||||||
@@ -25,10 +26,9 @@ let packet_name = null;
|
|||||||
let questions = null;
|
let questions = null;
|
||||||
let question_order = [];
|
let question_order = [];
|
||||||
let questions_correct = {};
|
let questions_correct = {};
|
||||||
window.number_of_questions = null;
|
|
||||||
let question_type = null;
|
let question_type = null;
|
||||||
let loaded_question = null;
|
let loaded_question = null;
|
||||||
window.review = false;
|
let review_mode = false;
|
||||||
let exam_time = null;
|
let exam_time = null;
|
||||||
let packet_time = null;
|
let packet_time = null;
|
||||||
let date_started = null;
|
let date_started = null;
|
||||||
@@ -403,8 +403,8 @@ function setUpQuestions(load_previous) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.number_of_questions = question_order.length;
|
exam_details.number_of_questions = question_order.length;
|
||||||
window.review = false;
|
review_mode = false;
|
||||||
|
|
||||||
// Horrible way to get type of questions
|
// Horrible way to get type of questions
|
||||||
// We assume they are all of the same type....
|
// We assume they are all of the same type....
|
||||||
@@ -658,7 +658,7 @@ function loadSession() {
|
|||||||
question_order = sessions[parseInt(s)].question_order;
|
question_order = sessions[parseInt(s)].question_order;
|
||||||
|
|
||||||
if (sessions[parseInt(s)].status == "complete") {
|
if (sessions[parseInt(s)].status == "complete") {
|
||||||
window.review = true;
|
review_mode = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If cancel is pressed or input is blank
|
// If cancel is pressed or input is blank
|
||||||
@@ -720,7 +720,7 @@ async function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == window.number_of_questions - 1) {
|
if (n == exam_details.number_of_questions - 1) {
|
||||||
$(".navigation[value='next']").attr("disabled", "disabled");
|
$(".navigation[value='next']").attr("disabled", "disabled");
|
||||||
} else {
|
} else {
|
||||||
$(".navigation[value='next']")
|
$(".navigation[value='next']")
|
||||||
@@ -1247,7 +1247,7 @@ function rebuildQuestionListPanel() {
|
|||||||
console.log("error - ", error);
|
console.log("error - ", error);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (window.review == true) {
|
if (review_mode == true) {
|
||||||
$(".question-panel-ans").remove();
|
$(".question-panel-ans").remove();
|
||||||
for (const qid in questions_correct) {
|
for (const qid in questions_correct) {
|
||||||
let q_no = question_order.indexOf(qid);
|
let q_no = question_order.indexOf(qid);
|
||||||
@@ -1306,16 +1306,16 @@ function createQuestionListPanel() {
|
|||||||
|
|
||||||
if (question_type == "rapid") {
|
if (question_type == "rapid") {
|
||||||
// Loop through all questions and append list items
|
// Loop through all questions and append list items
|
||||||
for (let n = 1; n < window.number_of_questions + 1; n++) {
|
for (let n = 1; n < exam_details.number_of_questions + 1; n++) {
|
||||||
appendQuestionListItem(n, "1");
|
appendQuestionListItem(n, "1");
|
||||||
appendQuestionListItem(n, "2").hide();
|
appendQuestionListItem(n, "2").hide();
|
||||||
}
|
}
|
||||||
} else if (question_type == "anatomy") {
|
} else if (question_type == "anatomy") {
|
||||||
for (let n = 1; n < window.number_of_questions + 1; n++) {
|
for (let n = 1; n < exam_details.number_of_questions + 1; n++) {
|
||||||
appendQuestionListItem(n, "1");
|
appendQuestionListItem(n, "1");
|
||||||
}
|
}
|
||||||
} else if (question_type == "long") {
|
} else if (question_type == "long") {
|
||||||
for (let n = 1; n < window.number_of_questions + 1; n++) {
|
for (let n = 1; n < exam_details.number_of_questions + 1; n++) {
|
||||||
appendQuestionListItem(n, "1");
|
appendQuestionListItem(n, "1");
|
||||||
appendQuestionListItem(n, "2");
|
appendQuestionListItem(n, "2");
|
||||||
appendQuestionListItem(n, "3");
|
appendQuestionListItem(n, "3");
|
||||||
@@ -1336,7 +1336,7 @@ $("#btn-local-file-load").click(function (evt) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(".submit-button").click(function (evt) {
|
$(".submit-button").click(function (evt) {
|
||||||
interact.submitAnswers(window, db, config, exam_details);
|
interact.submitAnswers(exam_details, db, config);
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#review-button").click(function (evt) {
|
$("#review-button").click(function (evt) {
|
||||||
@@ -1349,7 +1349,7 @@ $("#options-button").click(function (evt) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#review-overlay-button").click(function (evt) {
|
$("#review-overlay-button").click(function (evt) {
|
||||||
if (window.review == true) {
|
if (review_mode == true) {
|
||||||
reviewQuestions();
|
reviewQuestions();
|
||||||
} else {
|
} else {
|
||||||
$("#finish-dialog").modal();
|
$("#finish-dialog").modal();
|
||||||
@@ -1365,7 +1365,7 @@ $("#fullscreen-overlay-button").click(function (evt) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#finish-exam, #time-up-review-button").click(function (evt) {
|
$("#finish-exam, #time-up-review-button").click(function (evt) {
|
||||||
window.review = true;
|
review_mode = true;
|
||||||
reviewQuestions();
|
reviewQuestions();
|
||||||
$.modal.close();
|
$.modal.close();
|
||||||
});
|
});
|
||||||
@@ -1739,7 +1739,7 @@ function markAnswer(qid, current_question) {
|
|||||||
const type = current_question.type;
|
const type = current_question.type;
|
||||||
|
|
||||||
let option = null;
|
let option = null;
|
||||||
if (window.review == true) {
|
if (review_mode == true) {
|
||||||
// Disable all possible answer elements
|
// Disable all possible answer elements
|
||||||
$("#rapid-option").attr("disabled", "true");
|
$("#rapid-option").attr("disabled", "true");
|
||||||
$(".long-answer").attr("readonly", "true");
|
$(".long-answer").attr("readonly", "true");
|
||||||
@@ -2137,9 +2137,14 @@ $(document).ajaxStop(function () {
|
|||||||
$("#loading").hide();
|
$("#loading").hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
function saveSession() {
|
function saveSession(start_review) {
|
||||||
|
|
||||||
|
if (start_review == true) {
|
||||||
|
review_mode = true;
|
||||||
|
}
|
||||||
|
|
||||||
let status = "active";
|
let status = "active";
|
||||||
if (window.review == true) {
|
if (review_mode == true) {
|
||||||
status = "complete";
|
status = "complete";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2157,13 +2162,15 @@ function saveSession() {
|
|||||||
status: status,
|
status: status,
|
||||||
date: date_started,
|
date: date_started,
|
||||||
score: score,
|
score: score,
|
||||||
max_score: window.number_of_questions,
|
max_score: exam_details.number_of_questions,
|
||||||
exam_time: exam_time,
|
exam_time: exam_time,
|
||||||
time_left: time_remaining,
|
time_left: time_remaining,
|
||||||
question_order: question_order,
|
question_order: question_order,
|
||||||
questions_answered: 0, // TODO
|
questions_answered: 0, // TODO
|
||||||
total_questions: window.number_of_questions,
|
total_questions: exam_details.number_of_questions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.saveSession = saveSession;
|
//window.saveSession = saveSession;
|
||||||
|
|
||||||
|
$(document).on("saveSessionEvent", {}, (evt, review) => { saveSession(review) })
|
||||||
Reference in New Issue
Block a user