Code clean up: redundant semicolons

Made variable declaration style in for loops consistent
This commit is contained in:
2022-08-17 16:34:59 +01:00
parent 02290e968c
commit b15f76701e
5 changed files with 458 additions and 453 deletions

View File

@ -1,25 +1,25 @@
// Menu Highlight Scripts
const menuItems = document.getElementsByClassName('nav-link');
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');
menuItems[i].classList.add('active')
}
}
const dropdownItems = document.getElementsByClassName('dropdown-item');
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');
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');
var $form = $(this)
var data = $form.serialize()
var url = $(this).prop('action')
var rel_success = $(this).data('rel-success')
$.ajax({
url: url,
@ -28,25 +28,25 @@ $('form.form-post').submit(function(event) {
dataType: 'json',
success: function(response) {
if (response.redirect_to) {
window.location.href = response.redirect_to;
window.location.href = response.redirect_to
}
else {
window.location.href = rel_success;
window.location.href = rel_success
}
},
error: function(response) {
error_response(response);
error_response(response)
}
});
})
event.preventDefault();
});
event.preventDefault()
})
// Form Upload Questions - Special case, needs to handle files.
$('form[name=form-upload-questions]').submit(function(event) {
var $form = $(this);
var data = new FormData($form[0]);
var $form = $(this)
var data = new FormData($form[0])
var file = $('input[name=data_file]')[0].files[0]
data.append('file', file)
@ -57,21 +57,21 @@ $('form[name=form-upload-questions]').submit(function(event) {
processData: false,
contentType: false,
success: function(response) {
window.location.reload();
window.location.reload()
},
error: function(response) {
error_response(response);
error_response(response)
}
});
})
event.preventDefault();
});
event.preventDefault()
})
// Edit and Delete Test Button Handlers
$('.test-action').click(function(event) {
let id = $(this).data('id');
let action = $(this).data('action');
let id = $(this).data('id')
let action = $(this).data('action')
if (action == 'delete' || action == 'start' || action == 'end') {
$.ajax({
@ -80,25 +80,25 @@ $('.test-action').click(function(event) {
data: JSON.stringify({'id': id, 'action': action}),
contentType: 'application/json',
success: function(response) {
window.location.href = '/admin/tests/';
window.location.href = '/admin/tests/'
},
error: function(response){
error_response(response);
error_response(response)
},
});
})
} else if (action == 'edit') {
window.location.href = `/admin/test/${id}/`
}
event.preventDefault();
});
event.preventDefault()
})
// Edit Dataset Button Handlers
$('.edit-question-dataset').click(function(event) {
var id = $(this).data('id');
var action = $(this).data('action');
var disabled = $(this).hasClass('disabled');
var id = $(this).data('id')
var action = $(this).data('action')
var disabled = $(this).hasClass('disabled')
if ( !disabled ) {
if (action == 'delete') {
@ -111,25 +111,27 @@ $('.edit-question-dataset').click(function(event) {
}),
contentType: 'application/json',
success: function(response) {
window.location.reload();
window.location.reload()
},
error: function(response){
error_response(response);
error_response(response)
},
});
})
} else if (action == 'edit') {
window.location.href = `/admin/editor/${id}/`
} else if (action == 'view') {
window.location.href = `/admin/view/${id}`
} else if (action == 'download') {
window.location.href = `/admin/settings/questions/download/${id}/`
}
};
event.preventDefault();
});
}
event.preventDefault()
})
function error_response(response) {
const $alert = $("#alert-box");
$alert.html('');
const $alert = $("#alert-box")
$alert.html('')
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
$alert.html(`
@ -138,18 +140,18 @@ function error_response(response) {
${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 ++) {
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.html(output)
}
}
@ -167,20 +169,20 @@ $('#dismiss-cookie-alert').click(function(event){
},
dataType: 'json',
success: function(response){
console.log(response);
console.log(response)
},
error: function(response){
console.log(response);
console.log(response)
}
})
event.preventDefault();
event.preventDefault()
})
// Script for Result Actions
$('.result-action-buttons').click(function(event){
var id = $(this).data('id');
var id = $(this).data('id')
if ($(this).data('result-action') == 'generate') {
$.ajax({
@ -190,13 +192,13 @@ $('.result-action-buttons').click(function(event){
contentType: 'application/json',
dataType: 'html',
success: function(response) {
var display_window = window.open();
display_window.document.write(response);
var display_window = window.open()
display_window.document.write(response)
},
error: function(response){
error_response(response);
error_response(response)
},
});
})
} else {
var action = $(this).data('result-action')
$.ajax({
@ -206,23 +208,23 @@ $('.result-action-buttons').click(function(event){
contentType: 'application/json',
success: function(response) {
if (action == 'delete') {
window.location.href = '/admin/results/';
} else window.location.reload();
window.location.href = '/admin/results/'
} else window.location.reload()
},
error: function(response){
error_response(response);
error_response(response)
},
});
})
}
event.preventDefault();
});
event.preventDefault()
})
// Script for Deleting Time Adjustment
$('.adjustment-delete').click(function(event){
var user_code = $(this).data('user_code');
var location = window.location.href;
var user_code = $(this).data('user_code')
var location = window.location.href
location = location.replace('#', '')
$.ajax({
@ -231,12 +233,15 @@ $('.adjustment-delete').click(function(event){
data: JSON.stringify({'user_code': user_code}),
contentType: 'application/json',
success: function(response) {
window.location.reload();
window.location.reload()
},
error: function(response){
error_response(response);
error_response(response)
},
});
})
event.preventDefault()
})
event.preventDefault();
});