viveksantayana
2ba8980dd8
Corrected error display bug Removed redundant auth and models in quiz client app
86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
$(document).ready(function() {
|
|
$("#od-font-test").click(function(){
|
|
$("body").css("font-family", "opendyslexic3regular")
|
|
});
|
|
|
|
$('.test-code-input').keyup(function() {
|
|
var input = $(this).val().split("-").join("").split("—").join("");
|
|
if (input.length > 0) {
|
|
input = input.match(new RegExp('.{1,4}', 'g')).join("—");
|
|
}
|
|
$(this).val(input);
|
|
});
|
|
});
|
|
|
|
$('form[name=form-quiz-start]').submit(function(event) {
|
|
|
|
var $form = $(this);
|
|
var data = $form.serialize();
|
|
|
|
$.ajax({
|
|
url: window.location.pathname,
|
|
type: 'POST',
|
|
data: data,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
var _id = response._id
|
|
window.localStorage.setItem('_id', _id);
|
|
window.location.href = `/test/`;
|
|
},
|
|
error: function(response) {
|
|
error_response(response);
|
|
}
|
|
});
|
|
|
|
event.preventDefault();
|
|
});
|
|
|
|
function error_response(response) {
|
|
|
|
const $alert = $("#alert-box");
|
|
$alert.html('');
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
$alert.html(`
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<i class="bi bi-exclamation-triangle-fill" title="Danger"></i>
|
|
${response.responseJSON.error}
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
`);
|
|
} else if (response.responseJSON.error instanceof Array) {
|
|
var output = ''
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
output += `
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<i class="bi bi-exclamation-triangle-fill" title="Danger"></i>
|
|
${response.responseJSON.error[i]}
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
`;
|
|
$alert.html(output);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Dismiss Cookie Alert
|
|
$('#dismiss-cookie-alert').click(function(event){
|
|
|
|
$.ajax({
|
|
url: '/cookies/',
|
|
type: 'GET',
|
|
data: {
|
|
time: Date.now()
|
|
},
|
|
dataType: 'json',
|
|
success: function(response){
|
|
console.log(response);
|
|
},
|
|
error: function(response){
|
|
console.log(response);
|
|
}
|
|
})
|
|
|
|
event.preventDefault();
|
|
|
|
}) |