Finished data upload
Refactored to move security package inside common Moved data folder to process root.
This commit is contained in:
		@@ -350,13 +350,18 @@ $('form[name=form-update-account]').submit(function(event) {
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
$('.delete-test').click(function(event) {
 | 
			
		||||
$('form[name=form-create-test]').submit(function(event) {
 | 
			
		||||
    
 | 
			
		||||
    _id = $(this).data('_id')
 | 
			
		||||
    var $form = $(this);
 | 
			
		||||
    var alert = document.getElementById('alert-box');
 | 
			
		||||
    var data = $form.serialize();
 | 
			
		||||
    alert.innerHTML = ''
 | 
			
		||||
 | 
			
		||||
    $.ajax({
 | 
			
		||||
        url: `/admin/tests/delete/${_id}`,
 | 
			
		||||
        type: 'GET',
 | 
			
		||||
        url: window.location.pathname,
 | 
			
		||||
        type: 'POST',
 | 
			
		||||
        data: data,
 | 
			
		||||
        dataType: 'json',
 | 
			
		||||
        success: function(response) {
 | 
			
		||||
            window.location.href = '/admin/tests/';
 | 
			
		||||
        },
 | 
			
		||||
@@ -386,20 +391,78 @@ $('.delete-test').click(function(event) {
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Edit and Delete Test Button Handlers
 | 
			
		||||
 | 
			
		||||
$('form[name=form-create-test]').submit(function(event) {
 | 
			
		||||
$('form[name=form-upload-questions]').submit(function(event) {
 | 
			
		||||
    
 | 
			
		||||
    var $form = $(this);
 | 
			
		||||
    var alert = document.getElementById('alert-box');
 | 
			
		||||
    var data = $form.serialize();
 | 
			
		||||
    var data = new FormData($form[0]);
 | 
			
		||||
    var file = $('input[name=data_file]')[0].files[0]
 | 
			
		||||
    data.append('file', file)
 | 
			
		||||
    alert.innerHTML = ''
 | 
			
		||||
 | 
			
		||||
    $.ajax({
 | 
			
		||||
        url: window.location.pathname,
 | 
			
		||||
        type: 'POST',
 | 
			
		||||
        data: data,
 | 
			
		||||
        dataType: 'json',
 | 
			
		||||
        processData: false,
 | 
			
		||||
        contentType: false,
 | 
			
		||||
        success: function(response) {
 | 
			
		||||
            if (typeof response.success === 'string' || response.success instanceof String) {
 | 
			
		||||
                alert.innerHTML = alert.innerHTML + `
 | 
			
		||||
                <div class="alert alert-success alert-dismissible fade show" role="alert">
 | 
			
		||||
                    <i class="bi bi-exclamation-triangle-fill" title="Danger"></i>
 | 
			
		||||
                    ${response.success}
 | 
			
		||||
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
 | 
			
		||||
                </div>
 | 
			
		||||
                `;
 | 
			
		||||
            } else if (response.success instanceof Array) {
 | 
			
		||||
                for (var i = 0; i < response.success.length; i ++) {
 | 
			
		||||
                    alert.innerHTML = alert.innerHTML + `
 | 
			
		||||
                    <div class="alert alert-success alert-dismissible fade show" role="alert">
 | 
			
		||||
                        <i class="bi bi-exclamation-triangle-fill" title="Danger"></i>
 | 
			
		||||
                        ${response.success[i]}
 | 
			
		||||
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    `;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        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')
 | 
			
		||||
 | 
			
		||||
    $.ajax({
 | 
			
		||||
        url: `/admin/tests/delete/${_id}`,
 | 
			
		||||
        type: 'GET',
 | 
			
		||||
        success: function(response) {
 | 
			
		||||
            window.location.href = '/admin/tests/';
 | 
			
		||||
        },
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user