remove a few more window variables

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