.
This commit is contained in:
+57
-69
@@ -15,8 +15,7 @@ window.exam_details = {
|
|||||||
cid: "",
|
cid: "",
|
||||||
eid: 5678,
|
eid: 5678,
|
||||||
exam_mode: false,
|
exam_mode: false,
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
//window.exam_mode = false;
|
//window.exam_mode = false;
|
||||||
|
|
||||||
@@ -278,7 +277,9 @@ function loadPacketFromAjax(path) {
|
|||||||
})
|
})
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
//setUpPacket(data, path.split("/").pop());
|
//setUpPacket(data, path.split("/").pop());
|
||||||
if (data.hasOwnProperty("cached") && data["cached"]) { console.log("loading cached packet")}
|
if (data.hasOwnProperty("cached") && data["cached"]) {
|
||||||
|
console.log("loading cached packet");
|
||||||
|
}
|
||||||
setUpPacket(data, path);
|
setUpPacket(data, path);
|
||||||
$("#options-panel").hide();
|
$("#options-panel").hide();
|
||||||
})
|
})
|
||||||
@@ -387,7 +388,7 @@ cornerstoneWebImageLoader.external.cornerstone = cornerstone;
|
|||||||
|
|
||||||
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
|
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
|
||||||
|
|
||||||
cornerstone.imageCache.setMaximumSizeBytes(22428800)
|
cornerstone.imageCache.setMaximumSizeBytes(22428800);
|
||||||
|
|
||||||
// cornerstoneWADOImageLoader.configure({
|
// cornerstoneWADOImageLoader.configure({
|
||||||
// beforeSend: function(xhr) {
|
// beforeSend: function(xhr) {
|
||||||
@@ -452,7 +453,6 @@ function setUpPacket(data, path) {
|
|||||||
|
|
||||||
// If the question_requests is set we need to do a request for each question
|
// If the question_requests is set we need to do a request for each question
|
||||||
if (data.hasOwnProperty("question_requests") && data["question_requests"]) {
|
if (data.hasOwnProperty("question_requests") && data["question_requests"]) {
|
||||||
|
|
||||||
const question_total = Object.keys(data["questions"]).length;
|
const question_total = Object.keys(data["questions"]).length;
|
||||||
let question_number = 0;
|
let question_number = 0;
|
||||||
|
|
||||||
@@ -461,58 +461,46 @@ function setUpPacket(data, path) {
|
|||||||
|
|
||||||
// For loop to generate requests
|
// For loop to generate requests
|
||||||
(async () => {
|
(async () => {
|
||||||
for (const n in data["questions"]) {
|
for (const n in data["questions"]) {
|
||||||
const question_url = `${path}/${n}`;
|
const question_url = `${path}/${n}`;
|
||||||
question_number++;
|
question_number++;
|
||||||
|
|
||||||
console.log("Creating ", question_url, question_number, question_total);
|
console.log("Creating ", question_url, question_number, question_total);
|
||||||
//$("#progress").html(`Downloading [${question_number}/${question_total}]`);
|
//$("#progress").html(`Downloading [${question_number}/${question_total}]`);
|
||||||
let question_json = {}
|
let question_json = {};
|
||||||
try {
|
question_json = await interact
|
||||||
question_json = await interact.getQuestion(
|
.getQuestion(question_url, question_number, question_total)
|
||||||
question_url,
|
.fail((jqXHR, textStatus, errorThrown) => {
|
||||||
question_number,
|
console.log(jqXHR, textStatus, errorThrown);
|
||||||
question_total
|
console.log("error loading question");
|
||||||
).fail(( jqXHR, textStatus, errorThrown ) => {
|
data["questions"][n] = {};
|
||||||
console.log(jqXHR, textStatus, errorThrown);
|
});
|
||||||
console.log("error loading question");
|
|
||||||
data["questions"][n] = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
if (question_json.hasOwnProperty("cached") && question_json["cached"]) { console.log("loading cached packet")}
|
if (question_json.hasOwnProperty("cached") && question_json["cached"]) {
|
||||||
|
console.log("loading cached packet");
|
||||||
|
}
|
||||||
|
|
||||||
//requests.push(request)
|
if (
|
||||||
//request_numbers.push(n)
|
question_json.hasOwnProperty("images_json") &&
|
||||||
data["questions"][n] = question_json;
|
question_json["images_json"]
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
//requests.push(request)
|
||||||
console.log(error);
|
//request_numbers.push(n)
|
||||||
console.log("error loading question ", question_url);
|
|
||||||
|
|
||||||
question_json = await interact.getQuestion(
|
|
||||||
question_url,
|
|
||||||
question_number,
|
|
||||||
question_total
|
|
||||||
)
|
|
||||||
data["questions"][n] = question_json;
|
data["questions"][n] = question_json;
|
||||||
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Once all questions have been downloaded we carry on loading
|
||||||
}
|
loadSession();
|
||||||
// Once all questions have been downloaded we carry on loading
|
})();
|
||||||
loadSession();
|
|
||||||
})()
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Just carry on loading
|
// Just carry on loading
|
||||||
loadSession();
|
loadSession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadSession() {
|
function loadSession() {
|
||||||
console.log("load session")
|
console.log("load session");
|
||||||
// Either continue session or create a new one
|
// Either continue session or create a new one
|
||||||
window.db.session
|
window.db.session
|
||||||
// .where("status")
|
// .where("status")
|
||||||
@@ -803,7 +791,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
qid: qid,
|
qid: qid,
|
||||||
qidn: "1",
|
qidn: "1",
|
||||||
ans: evt.target.value,
|
ans: evt.target.value,
|
||||||
}
|
};
|
||||||
|
|
||||||
window.db.answers.put(answer);
|
window.db.answers.put(answer);
|
||||||
saveSession();
|
saveSession();
|
||||||
@@ -828,7 +816,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
qid: qid,
|
qid: qid,
|
||||||
qidn: "2",
|
qidn: "2",
|
||||||
ans: evt.target.value,
|
ans: evt.target.value,
|
||||||
}
|
};
|
||||||
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
|
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
|
||||||
window.db.answers.put(answer);
|
window.db.answers.put(answer);
|
||||||
|
|
||||||
@@ -911,7 +899,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
qid: qid,
|
qid: qid,
|
||||||
qidn: "1",
|
qidn: "1",
|
||||||
ans: evt.target.value,
|
ans: evt.target.value,
|
||||||
}
|
};
|
||||||
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
|
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
|
||||||
window.db.answers.put(answer);
|
window.db.answers.put(answer);
|
||||||
|
|
||||||
@@ -1000,7 +988,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
qid: qid,
|
qid: qid,
|
||||||
qidn: qidn,
|
qidn: qidn,
|
||||||
ans: evt.target.value,
|
ans: evt.target.value,
|
||||||
}
|
};
|
||||||
|
|
||||||
window.db.answers.put(answer);
|
window.db.answers.put(answer);
|
||||||
console.log("SAVE", qid, qidn, evt.target.value);
|
console.log("SAVE", qid, qidn, evt.target.value);
|
||||||
@@ -1056,7 +1044,9 @@ function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//rebuildQuestionListPanel();
|
//rebuildQuestionListPanel();
|
||||||
setTimeout(() => { setFocus(section); }, 200);
|
setTimeout(() => {
|
||||||
|
setFocus(section);
|
||||||
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1066,22 +1056,22 @@ function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
function setFocus(section) {
|
function setFocus(section) {
|
||||||
// Horrible (but it works)
|
// Horrible (but it works)
|
||||||
//setTimeout(function () {
|
//setTimeout(function () {
|
||||||
// In pratique it selects the end of a textarea but I'm not sure if I can be bothered...
|
// In pratique it selects the end of a textarea but I'm not sure if I can be bothered...
|
||||||
// Apparently I can...
|
// Apparently I can...
|
||||||
const el = $("*[data-answer-section-qidn=" + section + "]");
|
const el = $("*[data-answer-section-qidn=" + section + "]");
|
||||||
// If the target is a textarea we move focus and reapply the value
|
// If the target is a textarea we move focus and reapply the value
|
||||||
// to move the cursor to the end
|
// to move the cursor to the end
|
||||||
if (el.length < 1) {
|
if (el.length < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (el.get(0).type == "textarea") {
|
if (el.get(0).type == "textarea") {
|
||||||
const val = el.val();
|
const val = el.val();
|
||||||
el.focus().val("").val(val);
|
el.focus().val("").val(val);
|
||||||
// else we just focus
|
// else we just focus
|
||||||
} else {
|
} else {
|
||||||
el.focus();
|
el.focus();
|
||||||
}
|
}
|
||||||
//}, 200);
|
//}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1118,7 +1108,6 @@ function deleteQuestionListPanelFlags(answer) {
|
|||||||
answer.qidn +
|
answer.qidn +
|
||||||
" span"
|
" span"
|
||||||
).css("visibility", "hidden");
|
).css("visibility", "hidden");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateQuestionListPanelFlags(answer) {
|
function updateQuestionListPanelFlags(answer) {
|
||||||
@@ -1129,7 +1118,6 @@ function updateQuestionListPanelFlags(answer) {
|
|||||||
answer.qidn +
|
answer.qidn +
|
||||||
" span"
|
" span"
|
||||||
).css("visibility", "visible");
|
).css("visibility", "visible");
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Updates the question list panel
|
* Updates the question list panel
|
||||||
@@ -1982,7 +1970,8 @@ $("#btn-delete-databases").click(function (evt) {
|
|||||||
"This will delete ALL saved answers (including saved correct answers)!"
|
"This will delete ALL saved answers (including saved correct answers)!"
|
||||||
);
|
);
|
||||||
if (r == true) {
|
if (r == true) {
|
||||||
window.db.delete()
|
window.db
|
||||||
|
.delete()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
$.notify("Database successfully deleted", "success");
|
$.notify("Database successfully deleted", "success");
|
||||||
$.notify("The page will now reload", "warn");
|
$.notify("The page will now reload", "warn");
|
||||||
@@ -2097,4 +2086,3 @@ function saveSession() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.saveSession = saveSession;
|
window.saveSession = saveSession;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user