diff --git a/js/interact.js b/js/interact.js
index ae74430..13f48cb 100644
--- a/js/interact.js
+++ b/js/interact.js
@@ -2,16 +2,18 @@ import * as helper from "./helpers.js";
/**
* Submits answers
*/
-export function submitAnswers(exam_details, db) {
- console.log(
- getJsonAnswers(exam_details, db).then((a) => {
+export function submitAnswers(exam_details, db, config) {
+ getJsonAnswers(exam_details, db)
+ .then((a) => {
let json = {
eid: exam_details.eid,
answers: JSON.stringify(a),
};
- postAnswers(json);
+ postAnswers(json, config, exam_details);
})
- );
+ .catch((e) => {
+ alert("No answers to submit");
+ });
}
/**
@@ -19,24 +21,23 @@ export function submitAnswers(exam_details, db) {
* @return {JSON} - answers
*/
export function getJsonAnswers(exam_details, db) {
- const cid = exam_details.cid;
- const eid = exam_details.eid;
- return db.answers.where({ aid: aid, cid: cid, eid: eid }).toArray();
- // .then(function(ans) {
- // console.log(ans);
- // submitAnswers(ans);
- // });
+ return db.answers
+ .where({
+ aid: exam_details.aid,
+ cid: exam_details.cid,
+ eid: exam_details.eid,
+ })
+ .toArray();
}
/**
* Posts answers to url
* @param {*} ans - json representation of answers
*/
-export function postAnswers(ans) {
+export function postAnswers(ans, config, exam_details) {
$("#progress").html("Submitting answers...");
- // ans = {"test" : 1}
- console.log(ans);
- $.post(window.config.exam_submit_url, ans, null, "json")
+
+ $.post(config.exam_submit_url, ans, null, "json")
.done((data) => {
console.log("returned data", data);
if (data.success) {
@@ -52,8 +53,8 @@ export function postAnswers(ans) {
if (config.exam_results_url != "") {
let url = config.exam_results_url;
- if (window.exam_details.cid != "") {
- url = url + window.exam_details.cid;
+ if (exam_details.cid != "") {
+ url = url + exam_details.cid;
}
$("#options-link")
.empty()
@@ -117,7 +118,8 @@ export function getQuestion(url, question_number, question_total) {
url: url,
progress: function (e) {
$("#progress").html(
- `Downloading question [${question_number}/${question_total}]
This file is compressed (no size available)`)
+ `Downloading question [${question_number}/${question_total}]
This file is compressed (no size available)`
+ );
if (e.lengthComputable) {
var completedPercentage = Math.round((e.loaded * 100) / e.total);
@@ -128,11 +130,12 @@ export function getQuestion(url, question_number, question_total) {
);
}
},
- error: (jqXHR, textStatus, errorThrown) => { console.log("error downlading", jqXHR, textStatus, errorThrown) },
+ error: (jqXHR, textStatus, errorThrown) => {
+ console.log("error downlading", jqXHR, textStatus, errorThrown);
+ },
//success: function (data) {
// strReturn = data;
//},
//async: false,
});
-
}
diff --git a/js/main.js b/js/main.js
index b7b775d..5c6365e 100644
--- a/js/main.js
+++ b/js/main.js
@@ -10,7 +10,7 @@ import * as config from "./config.js";
//window.cid = "";
//window.eid = 5678;
-window.exam_details = {
+let exam_details = {
aid: null,
cid: "",
eid: 5678,
@@ -43,7 +43,7 @@ let use_local_question_cache = false;
//window.dfile = null;
-window.config = config;
+//config = config;
cornerstone.imageCache.setMaximumSizeBytes(5128800);
@@ -84,7 +84,6 @@ question_db.version(1).stores({
saved_exams: "eid, type, exam_mode, name, order, time, generated",
});
-
retrievePacketList();
/**
@@ -97,10 +96,10 @@ retrievePacketList();
function retrievePacketList() {
let url = "packets/";
- //console.log(window.config.exam_query_url);
+ //console.log(config.exam_query_url);
- if (window.config.exam_query_url != undefined) {
- url = window.config.exam_query_url;
+ if (config.exam_query_url != undefined) {
+ url = config.exam_query_url;
}
$.ajax({
@@ -372,7 +371,7 @@ function setUpQuestions(load_previous) {
Object.keys(questions).forEach(function (e) {
// Store question data into dexie
let d = {
- eid: window.exam_details.eid,
+ eid: exam_details.eid,
qid: e,
data: questions[e],
};
@@ -396,8 +395,8 @@ function setUpQuestions(load_previous) {
}
let randomise_order = true;
- if (window.config.randomise_order != undefined) {
- randomise_order = window.config.randomise_order;
+ if (config.randomise_order != undefined) {
+ randomise_order = config.randomise_order;
}
if (randomise_order) {
question_order = helper.shuffleArray(question_order);
@@ -411,7 +410,7 @@ function setUpQuestions(load_previous) {
// We assume they are all of the same type....
//question_type = questions[Object.keys(questions)[0]].type;
- if (window.exam_details.exam_mode) {
+ if (exam_details.exam_mode) {
$("#options-button, #review-overlay-button").hide();
} else {
$("#submit-button").hide();
@@ -438,12 +437,12 @@ function setUpQuestions(load_previous) {
exam_time = $(".exam-time").val() * 60;
});
- if (window.exam_details.exam_mode) {
+ if (exam_details.exam_mode) {
// NOTE: changing the CID when restoring a session will not affect the time left
$("#candidate-number2")
- .val(window.exam_details.cid)
+ .val(exam_details.cid)
.change(() => {
- window.exam_details.cid = parseInt($("#candidate-number2").val());
+ exam_details.cid = parseInt($("#candidate-number2").val());
});
$("#start-dialog").addClass("no-close");
@@ -464,8 +463,6 @@ function setUpQuestions(load_previous) {
createQuestionListPanel();
}
-
-
/**
* Parse the packet and extract metadata (if it exists)
* Will then call setUpQuestions() to load the packet
@@ -480,7 +477,7 @@ function setUpPacket(data, path) {
$(".exam-name").text("Exam: " + packet_name);
if (data.hasOwnProperty("eid")) {
- window.exam_details.eid = data.eid;
+ exam_details.eid = data.eid;
}
if (data.hasOwnProperty("exam_type")) {
@@ -564,7 +561,7 @@ function setUpPacket(data, path) {
// Store question data into dexie
let d = {
- eid: window.exam_details.eid,
+ eid: exam_details.eid,
qid: n,
data: question_json,
};
@@ -605,11 +602,11 @@ function loadSession() {
// Start new session if no session found
if (sessions.length < 1) {
- window.exam_details.aid = uuidv4();
+ exam_details.aid = uuidv4();
date_started = Date.now();
} else {
let text = "Select session to continue (leave blank to create new):";
- if (window.exam_details.exam_mode) {
+ if (exam_details.exam_mode) {
text = "Session will be continued";
}
//console.log(sessions.date);
@@ -640,7 +637,7 @@ function loadSession() {
// If in exam mode we don't want to allow multiple sessions
let s;
- if (window.exam_details.exam_mode) {
+ if (exam_details.exam_mode) {
s = "0";
alert(text);
} else {
@@ -650,8 +647,8 @@ function loadSession() {
if (s != null && s != "") {
load_previous = true;
- window.exam_details.aid = sessions[parseInt(s)].aid;
- window.exam_details.cid = sessions[parseInt(s)].cid;
+ exam_details.aid = sessions[parseInt(s)].aid;
+ exam_details.cid = sessions[parseInt(s)].cid;
date_started = sessions[parseInt(s)].date;
let time_left = sessions[parseInt(s)].time_left;
@@ -665,7 +662,7 @@ function loadSession() {
}
} else {
// If cancel is pressed or input is blank
- window.exam_details.aid = uuidv4();
+ exam_details.aid = uuidv4();
date_started = Date.now();
//console.log("new date", date_started);
}
@@ -683,9 +680,9 @@ function loadSession() {
*/
async function loadQuestion(n, section = 1, force_reload = false) {
$("#question-loading").show();
- const aid = window.exam_details.aid;
- const cid = window.exam_details.cid;
- const eid = window.exam_details.eid;
+ const aid = exam_details.aid;
+ const cid = exam_details.cid;
+ const eid = exam_details.eid;
// Make sure we have an integer
n = parseInt(n);
@@ -1213,9 +1210,9 @@ function updateQuestionListPanelFlags(answer) {
* if it gets slow...)
*/
function rebuildQuestionListPanel() {
- const aid = window.exam_details.aid;
- const cid = window.exam_details.cid;
- const eid = window.exam_details.eid;
+ const aid = exam_details.aid;
+ const cid = exam_details.cid;
+ const eid = exam_details.eid;
//console.log("UP");
db.answers
@@ -1339,7 +1336,7 @@ $("#btn-local-file-load").click(function (evt) {
});
$(".submit-button").click(function (evt) {
- interact.submitAnswers(window, db);
+ interact.submitAnswers(window, db, config, exam_details);
});
$("#review-button").click(function (evt) {
@@ -1440,8 +1437,8 @@ function reviewQuestions() {
timer.stop();
}
- const cid = window.exam_details.cid;
- const eid = window.exam_details.eid;
+ const cid = exam_details.cid;
+ const eid = exam_details.eid;
$("#review-overlay").show();
$("#review-answer-list").empty();
$("#review-answer-table").empty();
@@ -1910,9 +1907,9 @@ function answerInArray(arr, ans) {
}
function addFlagEvents() {
- const aid = window.exam_details.aid;
- const cid = window.exam_details.cid;
- const eid = window.exam_details.eid;
+ const aid = exam_details.aid;
+ const cid = exam_details.cid;
+ const eid = exam_details.eid;
// Bind flag change events
$("button.flag").click(function (event) {
@@ -1945,9 +1942,9 @@ function addFlagEvents() {
// Loads the current question flag status and updates display
function loadFlagsFromDb(qid, n) {
- const aid = window.exam_details.aid;
- const cid = window.exam_details.cid;
- const eid = window.exam_details.eid;
+ const aid = exam_details.aid;
+ const cid = exam_details.cid;
+ const eid = exam_details.eid;
db.flags
.get({ aid: aid, cid: cid, eid: eid, qid: qid, qidn: n })
.then(function (answer) {
@@ -1967,12 +1964,12 @@ function showLoginDialog() {
}
$("#start-exam-button").click(function (evt) {
- window.exam_details.cid = parseInt($("#candidate-number").val());
+ exam_details.cid = parseInt($("#candidate-number").val());
$.modal.close();
});
$(".start-packet-button").click(function (evt) {
- if (window.exam_details.exam_mode) {
+ if (exam_details.exam_mode) {
if (!Number.isInteger(parseInt($("#candidate-number2").val()))) {
alert("Please enter a valid candidate number.");
return;
@@ -1991,7 +1988,7 @@ $(".start-packet-button").click(function (evt) {
$("#timer").html("Time left: " + timer.getTimeValues().toString());
});
timer.addEventListener("targetAchieved", function (e) {
- if (window.exam_details.exam_mode == true) {
+ if (exam_details.exam_mode == true) {
$(
"#dialog-submit-button, #time-up-review-button, #time-up-continue-button"
).toggle();
@@ -2155,8 +2152,8 @@ function saveSession() {
time_values.seconds;
db.session.put({
packet: packet_name,
- aid: window.exam_details.aid,
- cid: window.exam_details.cid,
+ aid: exam_details.aid,
+ cid: exam_details.cid,
status: status,
date: date_started,
score: score,