diff --git a/ref-test/admin/models/tests.py b/ref-test/admin/models/tests.py
index 2ba8573..6605ea8 100644
--- a/ref-test/admin/models/tests.py
+++ b/ref-test/admin/models/tests.py
@@ -14,7 +14,7 @@ class Test:
self._id = _id
self.start_date = start_date
self.expiry_date = expiry_date
- self.time_limit = None if time_limit == 'none' or time_limit == '' else int(time_limit)
+ self.time_limit = None if time_limit == 'none' or time_limit == '' or time_limit == None else int(time_limit)
self.creator = creator
self.dataset = dataset
diff --git a/ref-test/admin/static/css/style.css b/ref-test/admin/static/css/style.css
index d719dc2..6672d33 100644
--- a/ref-test/admin/static/css/style.css
+++ b/ref-test/admin/static/css/style.css
@@ -20,7 +20,7 @@ body {
padding-bottom: 40px;
}
-.form-signin {
+.form-display {
width: 100%;
max-width: 420px;
padding: 15px;
diff --git a/ref-test/admin/static/js/script.js b/ref-test/admin/static/js/script.js
index ad4cd34..23cfe3c 100644
--- a/ref-test/admin/static/js/script.js
+++ b/ref-test/admin/static/js/script.js
@@ -13,392 +13,37 @@ for(let i = 0; i< dropdownItems.length; i++) {
}
}
-// Form Processing Scripts
-$('form[name=form-register]').submit(function(event) {
+// General Post Method Form Processing Script
+$('form.form-post').submit(function(event) {
var $form = $(this);
- var alert = document.getElementById('alert-box');
var data = $form.serialize();
-
- alert.innerHTML = '';
+ var url = $(this).attr('action');
+ var rel_success = $(this).data('rel-success');
$.ajax({
- url: window.location.pathname,
+ url: url,
type: 'POST',
data: data,
dataType: 'json',
success: function(response) {
- window.location.href = "/admin/login/";
+ window.location.href = rel_success;
},
error: function(response) {
- if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- event.preventDefault();
-});
-
-$('form[name=form-login]').submit(function(event) {
-
- var $form = $(this);
- var alert = document.getElementById('alert-box');
- var data = $form.serialize();
-
- alert.innerHTML = '';
-
- $.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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- event.preventDefault();
-});
-
-$('form[name=form-reset]').submit(function(event) {
-
- var $form = $(this);
- var alert = document.getElementById('alert-box');
- var data = $form.serialize();
-
- alert.innerHTML = '';
-
- $.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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- 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)
- alert.innerHTML = '';
-
- $.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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- event.preventDefault();
-});
-
-$('form[name=form-create-user]').submit(function(event) {
-
- var $form = $(this);
- var alert = document.getElementById('alert-box');
- var data = $form.serialize();
-
- alert.innerHTML = '';
-
- $.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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- event.preventDefault();
-});
-
-$('form[name=form-delete-user]').submit(function(event) {
-
- var $form = $(this);
- var alert = document.getElementById('alert-box');
- var data = $form.serialize();
-
- alert.innerHTML = '';
-
- $.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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- event.preventDefault();
-});
-
-$('form[name=form-update-user]').submit(function(event) {
-
- var $form = $(this);
- var alert = document.getElementById('alert-box');
- var data = $form.serialize();
-
- alert.innerHTML = '';
-
- $.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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- event.preventDefault();
-});
-
-$('form[name=form-update-account]').submit(function(event) {
-
- var $form = $(this);
- var alert = document.getElementById('alert-box');
- var data = $form.serialize();
-
- alert.innerHTML = '';
-
- $.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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
-
- event.preventDefault();
-});
-
-$('form[name=form-create-test]').submit(function(event) {
-
- var $form = $(this);
- var alert = document.getElementById('alert-box');
- var data = $form.serialize();
- alert.innerHTML = '';
-
- $.ajax({
- url: window.location.pathname,
- type: 'POST',
- data: data,
- dataType: 'json',
- 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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
+ error_response(response);
}
});
event.preventDefault();
});
+// Form Upload Questions - Special case, needs to handle files.
$('form[name=form-upload-questions]').submit(function(event) {
var $form = $(this);
- var alert = document.getElementById('alert-box');
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,
@@ -410,153 +55,84 @@ $('form[name=form-upload-questions]').submit(function(event) {
window.location.reload();
},
error: function(response) {
- if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
+ error_response(response);
}
});
event.preventDefault();
});
-
// Edit and Delete Test Button Handlers
$('.delete-test').click(function(event) {
- _id = $(this).data('_id')
-
+ let _id = $(this).data('_id')
$.ajax({
- url: `/admin/tests/delete/${_id}`,
- type: 'GET',
+ url: `/admin/tests/delete/`,
+ type: 'POST',
+ data: JSON.stringify({'_id': _id}),
+ contentType: 'application/json',
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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
+ error: function(response){
+ error_response(response);
+ },
});
event.preventDefault();
});
-// 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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
- });
- };
- event.preventDefault();
-});
-
+// Edit Dataset Button Handlers
$('.edit-question-dataset').click(function(event) {
- var alert = document.getElementById('alert-box');
- alert.innerHTML = '';
-
var filename = $(this).data('filename');
+ var action = $(this).data('action');
var disabled = $(this).hasClass('disabled');
- if ( !disabled ) {
+ if ( !disabled ) {
$.ajax({
- url: `/admin/settings/questions/default/${filename}`,
- type: 'GET',
+ url: `/admin/settings/questions/${action}/`,
+ type: 'POST',
+ data: JSON.stringify({'filename': filename}),
+ contentType: 'application/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 + `
-
-
- ${response.responseJSON.error}
-
-
- `;
- } else if (response.responseJSON.error instanceof Array) {
- for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.innerHTML = alert.innerHTML + `
-
-
- ${response.responseJSON.error[i]}
-
-
- `;
- }
- }
- }
+ error: function(response){
+ error_response(response);
+ },
});
};
event.preventDefault();
});
+function error_response(response) {
+
+ var alert = $("#alert-box");
+ alert.html('');
+
+ if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
+ alert.html(`
+
+
+ ${response.responseJSON.error}
+
+
+ `);
+ } else if (response.responseJSON.error instanceof Array) {
+ for (var i = 0; i < response.responseJSON.error.length; i ++) {
+ alert.html(`
+
+
+ ${response.responseJSON.error[i]}
+
+
+ `);
+ }
+ }
+}
+
// Dismiss Cookie Alert
$('#dismiss-cookie-alert').click(function(event){
diff --git a/ref-test/admin/templates/admin/auth/account.html b/ref-test/admin/templates/admin/auth/account.html
index 28ca8af..1043fc9 100644
--- a/ref-test/admin/templates/admin/auth/account.html
+++ b/ref-test/admin/templates/admin/auth/account.html
@@ -2,9 +2,9 @@
{% block content %}