few fixes

This commit is contained in:
Ross
2021-02-01 12:09:46 +00:00
parent 9ede509839
commit d066d283a4
2 changed files with 68 additions and 50 deletions
+1 -1
View File
@@ -18,7 +18,7 @@
<div class="content-panel"> <div class="content-panel">
<div class="nav-bar"> <div class="nav-bar">
<button id="review-button" class="navigation nav-right"><b></b></button> <button id="review-button" class="navigation nav-right"><b></b></button>
<button class="submit-button navigation nav-right"><b>submit</b></button> <button id="nav-submit-button" class="submit-button navigation nav-right"><b>submit</b></button>
<button id="options-button" class="navigation nav-right" <button id="options-button" class="navigation nav-right"
title="click to load new packet or manage saved answers">options</button> title="click to load new packet or manage saved answers">options</button>
<button id="review-overlay-button" class="navigation nav-right" <button id="review-overlay-button" class="navigation nav-right"
+67 -49
View File
@@ -4,9 +4,9 @@
export function submitAnswers(window, db) { export function submitAnswers(window, db) {
console.log( console.log(
getJsonAnswers(window, db).then((a) => { getJsonAnswers(window, db).then((a) => {
let json = { let json = {
"eid": window.eid, eid: window.eid,
"answers": JSON.stringify(a), answers: JSON.stringify(a),
}; };
postAnswers(json); postAnswers(json);
}) })
@@ -34,59 +34,77 @@ export function getJsonAnswers(window, db) {
export function postAnswers(ans) { export function postAnswers(ans) {
$("#progress").html("Submitting answers..."); $("#progress").html("Submitting answers...");
// ans = {"test" : 1} // ans = {"test" : 1}
console.log(ans) console.log(ans);
$.post(window.config.exam_submit_url, ans, null, "json").done((data) => { $.post(window.config.exam_submit_url, ans, null, "json")
console.log(data); .done((data) => {
if (data.success) { console.log("returned data", data);
if (data.question_count == window.number_of_questions) { if (data.success) {
let ret = confirm( $("#submit-error-overlay").remove();
`${data.question_count} answers sucessfully submitted. Click OK to finish the exam.` 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) { if (ret) {
window.review = true; window.review = true;
window.saveSession(); window.saveSession();
if (config.exam_results_url != "") { if (config.exam_results_url != "") {
let url = config.exam_results_url; let url = config.exam_results_url;
if (window.cid != "") { if (window.cid != "") {
url = url + window.cid; url = url + window.cid;
}
$("#options-link")
.empty()
.append(
`<a href="${url}" target="_blank"><div class="packet-button">Results and answers</div></a>`
);
} }
$("#options-link") $("#options-panel").show();
.empty() } else {
.append(
`<a href="${url}" target="_blank"><div class="packet-button">Results and answers</div></a>`
);
} }
$("#options-panel").show();
} else { } else {
alert(`${data.question_count} answers sucessfully submitted.`);
} }
} else { } else {
alert(`${data.question_count} answers sucessfully submitted.`); submissionError(data, ans);
} }
} else { })
alert(`Error submitting answers: ${data.error}`); .fail((e) => {
var docHeight = $(document).height(); // Will occur with server error such as 500
console.log("error", e);
$("body").append( submissionError(e, ans);
`<div id='overlay'><span style='color: white'><p>An error has occured when submit your answers. A copy of your answers are displayed below, you may wish to save a copy. Please refresh this page to continue.</p>${JSON.stringify( });
ans
)}</span></div>`
);
$("#overlay").height(docHeight).css({
opacity: 0.9,
position: "absolute",
top: 0,
left: 0,
"background-color": "black",
width: "100%",
"user-select": "text",
"-moz-user-select": "text",
"-webkit-user-select": "text",
"z-index": 5000,
});
}
});
// $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans)); // $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
} }
function submissionError(data, ans) {
// error will not be defined with server errors
if (data.error != undefined) {
alert(`Error submitting answers: ${data.error}`);
} else {
alert(`Error submitting answers`);
}
var docHeight = $(document).height();
$("body").append(
`<div id='submit-error-overlay'><span style='color: white'><p>An error has occured when submit your answers. A copy of your answers are displayed below, you may wish to save a copy. Please try submitting again or refresh this page to continue.</p>${JSON.stringify(
ans
)}</span></div>`
);
$("#nav-submit-button").prependTo("#submit-error-overlay");
$("#submit-error-overlay").height(docHeight).css({
opacity: 0.9,
position: "absolute",
top: 0,
left: 0,
"background-color": "black",
width: "100%",
"user-select": "text",
"-moz-user-select": "text",
"-webkit-user-select": "text",
"z-index": 5000,
});
}