Vivek Santayana
02290e968c
Added view questions panel to editor interface Added view questions section of web site Added links to navbars
115 lines
3.3 KiB
JavaScript
115 lines
3.3 KiB
JavaScript
// 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')
|
|
}
|
|
}
|
|
|
|
// General Post Method Form Processing Script
|
|
$('form.form-post').submit(function(event) {
|
|
|
|
var $form = $(this)
|
|
var data = $form.serialize()
|
|
var url = $(this).prop('action')
|
|
var rel_success = $(this).data('rel-success')
|
|
|
|
$.ajax({
|
|
url: url,
|
|
type: 'POST',
|
|
data: data,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
if (response.redirect_to) {
|
|
window.location.href = response.redirect_to
|
|
}
|
|
else {
|
|
window.location.href = rel_success
|
|
}
|
|
},
|
|
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 (let 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)
|
|
}
|
|
}
|
|
|
|
$alert.focus()
|
|
}
|
|
|
|
// Dismiss Cookie Alert
|
|
$('#dismiss-cookie-alert').click(function(event){
|
|
|
|
$.ajax({
|
|
url: '/cookies/',
|
|
type: 'POST',
|
|
data: {
|
|
time: Date.now()
|
|
},
|
|
dataType: 'json',
|
|
success: function(response){
|
|
console.log(response)
|
|
},
|
|
error: function(response){
|
|
console.log(response)
|
|
}
|
|
})
|
|
|
|
event.preventDefault()
|
|
})
|
|
|
|
// Create New Dataset
|
|
$('.create-new-dataset').click(function(event){
|
|
$.ajax({
|
|
url: '/api/editor/new/',
|
|
type: 'POST',
|
|
data: {
|
|
time: Date.now()
|
|
},
|
|
dataType: 'json',
|
|
success: function(response){
|
|
if (response.redirect_to) {
|
|
window.location.href = response.redirect_to
|
|
}
|
|
},
|
|
error: function(response){
|
|
console.log(response)
|
|
}
|
|
})
|
|
event.preventDefault()
|
|
}) |