2021-11-23 13:00:03 +00:00
|
|
|
// Menu Highlight Scripts
|
|
|
|
const menuItems = document.getElementsByClassName('nav-link');
|
|
|
|
for(let i = 0; i < menuItems.length; i++) {
|
|
|
|
if(menuItems[i].pathname == window.location.pathname) {
|
|
|
|
menuItems[i].classList.add('active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const dropdownItems = document.getElementsByClassName('dropdown-item');
|
|
|
|
for(let i = 0; i< dropdownItems.length; i++) {
|
|
|
|
if(dropdownItems[i].pathname == window.location.pathname) {
|
|
|
|
dropdownItems[i].classList.add('active');
|
|
|
|
$( "#" + dropdownItems[i].id ).closest( '.dropdown' ).find('.dropdown-toggle').addClass('active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form Processing Scripts
|
|
|
|
$('form[name=form-register]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.href = "/admin/login/";
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form[name=form-login]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.href = "/admin/dashboard/";
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form[name=form-reset]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.href = "/admin/login/";
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form[name=form-update-password]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
console.log(data)
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.href = "/admin/login/";
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form[name=form-create-user]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form[name=form-delete-user]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.href = '/admin/settings/users/';
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form[name=form-update-user]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.href = '/admin/settings/users';
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form[name=form-update-account]').submit(function(event) {
|
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.href = '/admin/dashboard/';
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
2021-11-24 17:17:56 +00:00
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2021-11-28 02:30:46 +00:00
|
|
|
$('form[name=form-create-test]').submit(function(event) {
|
2021-11-25 20:12:50 +00:00
|
|
|
|
2021-11-28 02:30:46 +00:00
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
var data = $form.serialize();
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-25 20:12:50 +00:00
|
|
|
|
|
|
|
$.ajax({
|
2021-11-28 02:30:46 +00:00
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
2021-11-25 20:12:50 +00:00
|
|
|
success: function(response) {
|
|
|
|
window.location.href = '/admin/tests/';
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2021-11-28 02:30:46 +00:00
|
|
|
$('form[name=form-upload-questions]').submit(function(event) {
|
2021-11-24 17:17:56 +00:00
|
|
|
|
|
|
|
var $form = $(this);
|
|
|
|
var alert = document.getElementById('alert-box');
|
2021-11-28 02:30:46 +00:00
|
|
|
var data = new FormData($form[0]);
|
|
|
|
var file = $('input[name=data_file]')[0].files[0]
|
|
|
|
data.append('file', file)
|
2021-11-28 17:28:14 +00:00
|
|
|
alert.innerHTML = '';
|
2021-11-24 17:17:56 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
2021-11-28 02:30:46 +00:00
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
success: function(response) {
|
2021-11-28 17:28:14 +00:00
|
|
|
window.location.reload();
|
2021-11-28 02:30:46 +00:00
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Edit and Delete Test Button Handlers
|
|
|
|
$('.delete-test').click(function(event) {
|
|
|
|
|
|
|
|
_id = $(this).data('_id')
|
2021-11-28 17:28:14 +00:00
|
|
|
|
2021-11-28 02:30:46 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: `/admin/tests/delete/${_id}`,
|
|
|
|
type: 'GET',
|
2021-11-24 17:17:56 +00:00
|
|
|
success: function(response) {
|
2021-11-25 20:12:50 +00:00
|
|
|
window.location.href = '/admin/tests/';
|
2021-11-24 17:17:56 +00:00
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
2021-11-23 13:00:03 +00:00
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
// Edit and Delete Dataset Button Handlers
|
|
|
|
$('.delete-question-dataset').click(function(event) {
|
|
|
|
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
alert.innerHTML = '';
|
|
|
|
|
|
|
|
var filename = $(this).data('filename');
|
|
|
|
var disabled = $(this).hasClass('disabled');
|
|
|
|
|
|
|
|
if ( !disabled ) {
|
|
|
|
$.ajax({
|
|
|
|
url: `/admin/settings/questions/delete/${filename}`,
|
|
|
|
type: 'GET',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.edit-question-dataset').click(function(event) {
|
|
|
|
|
|
|
|
var alert = document.getElementById('alert-box');
|
|
|
|
alert.innerHTML = '';
|
|
|
|
|
|
|
|
var filename = $(this).data('filename');
|
|
|
|
var disabled = $(this).hasClass('disabled');
|
|
|
|
|
|
|
|
if ( !disabled ) {
|
|
|
|
$.ajax({
|
|
|
|
url: `/admin/settings/questions/default/${filename}`,
|
|
|
|
type: 'GET',
|
|
|
|
success: function(response) {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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) {
|
|
|
|
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
|
|
|
alert.innerHTML = alert.innerHTML + `
|
|
|
|
<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>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2021-11-23 13:00:03 +00:00
|
|
|
// Dismiss Cookie Alert
|
|
|
|
$('#dismiss-cookie-alert').click(function(event){
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: '/cookies/',
|
|
|
|
type: 'GET',
|
|
|
|
data: {
|
|
|
|
time: Date.now()
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response){
|
2021-11-28 17:28:14 +00:00
|
|
|
console.log(response);
|
2021-11-23 13:00:03 +00:00
|
|
|
},
|
|
|
|
error: function(response){
|
2021-11-28 17:28:14 +00:00
|
|
|
console.log(response);
|
2021-11-23 13:00:03 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-11-28 17:28:14 +00:00
|
|
|
event.preventDefault();
|
2021-11-23 13:00:03 +00:00
|
|
|
|
|
|
|
})
|