few fixes
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@
|
||||
<div class="content-panel">
|
||||
<div class="nav-bar">
|
||||
<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"
|
||||
title="click to load new packet or manage saved answers">options</button>
|
||||
<button id="review-overlay-button" class="navigation nav-right"
|
||||
|
||||
+28
-10
@@ -5,8 +5,8 @@ export function submitAnswers(window, db) {
|
||||
console.log(
|
||||
getJsonAnswers(window, db).then((a) => {
|
||||
let json = {
|
||||
"eid": window.eid,
|
||||
"answers": JSON.stringify(a),
|
||||
eid: window.eid,
|
||||
answers: JSON.stringify(a),
|
||||
};
|
||||
postAnswers(json);
|
||||
})
|
||||
@@ -34,10 +34,12 @@ export function getJsonAnswers(window, db) {
|
||||
export function postAnswers(ans) {
|
||||
$("#progress").html("Submitting answers...");
|
||||
// ans = {"test" : 1}
|
||||
console.log(ans)
|
||||
$.post(window.config.exam_submit_url, ans, null, "json").done((data) => {
|
||||
console.log(data);
|
||||
console.log(ans);
|
||||
$.post(window.config.exam_submit_url, ans, null, "json")
|
||||
.done((data) => {
|
||||
console.log("returned data", data);
|
||||
if (data.success) {
|
||||
$("#submit-error-overlay").remove();
|
||||
if (data.question_count == window.number_of_questions) {
|
||||
let ret = confirm(
|
||||
`${data.question_count} answers sucessfully submitted. Click OK to finish the exam.`
|
||||
@@ -65,16 +67,35 @@ export function postAnswers(ans) {
|
||||
alert(`${data.question_count} answers sucessfully submitted.`);
|
||||
}
|
||||
} else {
|
||||
submissionError(data, ans);
|
||||
}
|
||||
})
|
||||
.fail((e) => {
|
||||
// Will occur with server error such as 500
|
||||
console.log("error", e);
|
||||
submissionError(e, 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='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(
|
||||
`<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>`
|
||||
);
|
||||
|
||||
$("#overlay").height(docHeight).css({
|
||||
$("#nav-submit-button").prependTo("#submit-error-overlay");
|
||||
|
||||
$("#submit-error-overlay").height(docHeight).css({
|
||||
opacity: 0.9,
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
@@ -87,6 +108,3 @@ export function postAnswers(ans) {
|
||||
"z-index": 5000,
|
||||
});
|
||||
}
|
||||
});
|
||||
// $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user