Commit cea09657 authored by William Paul Liggett's avatar William Paul Liggett

Admin Page: The edit test capability fully works now! Uses PHP, JS, and Ajax to do its magic.

parent e91fc287
......@@ -9,7 +9,7 @@
* Purpose: Function to standardise the output of various Ajax requests using JSON as the data storage.
* -------------------------------------------------------------------------------------------------------------- */
function output_json_response($successful, $error_message) {
function output_json_response($successful = false, $error_message = "Incorrect usage.") {
// Ensures the variables must be set correctly.
if(!isset($successful) || !is_bool($successful)) {
$successful = false;
......@@ -34,12 +34,13 @@ $test_condition = intval($_POST['edit_test_condition']); // The kind of test be
// Validate the data.
if($sk <= 0 || $subject_id <= 0 || $test_condition <= 0) {
output_json_response(false, "The surrogate key (sk), subject_id, nor the test_condition can be <= 0.");
output_json_response(false, "The surrogate key (sk), subject_id, nor the test_condition cannot be less than or equal to zero.");
else if($test_condition > 4) {
output_json_response(false, "The test_condition cannot be greater than 4.");
// Logs into the OpenVigilance Task tests database to control and alter user tests.
......@@ -30,15 +30,25 @@
<h1>OpenVigilance Task: Change Log</h1>
<h2>Programmer: William Paul Liggett (</h2>
<p><em>Total labor time: 20.5 hours.</em></p>
<p><em>Total labor time: 28.5 hours.</em></p>
<p class="version_info"><strong>To Do:</strong></p>
<li>Admin Page: Capability to add, edit, and remove user tests.</li>
<li>Admin Page: Capability to add and remove user tests.</li>
<li>Subject Login Page: Allow a test participant to login if they have a test scheduled.</li>
<li>Vigilance Tests: Record the activity of each subject during the test and save it as a CSV data file on the server.</li>
<li>Admin Page: Add a section to show the stored CSV files so that they can be downloaded or deleted at will.</li>
<p class="version_info">Version 1.5.0 (2018-02-21 to 2018-02-25):</p>
<p><em>Estimated labor time: 8 hours.</em></p>
Admin Page: The capability to edit tests have been fully implemented! Utilizes advanced JavaScript, GUI controls,
Ajax, and PHP to keep the front-and-backend aspects in sync.
<li>Implemented PHP user sessions to help improve the security and to incorporate more advanced web app functionality.</li>
<p class="version_info">Version 1.4.1 (2018-02-20):</p>
<p><em>Estimated labor time: 1 hour.</em></p>
......@@ -6,6 +6,17 @@
If a copy of the MPL was not distributed with this file, You can obtain one at
------------------------------------------------------------------------------------------------------------------ */
// GLOBAL VARS: Keeps track of which row (scheduled OV test) the admin is adding, editing, or removing.
var DOMelem_radio_btn_selected;
var scheduled_sk;
var scheduled_subject_id;
var scheduled_test_condition;
var scheduled_login_code;
var new_scheduled_subject_id;
var new_scheduled_test_condition;
;(function(window, $) {
$(document).ready(function() {
// Edit Test
......@@ -69,6 +80,9 @@
if(valid) {
new_scheduled_subject_id = $("#edit_test_subject_id").val();
new_scheduled_test_condition = $("#edit_test_condition").val();
// The data sent to the server is what the admin wanted modified via the pop-up dialog defined further below.
// Specifically, see the Getters and Setters near the bottom.
......@@ -77,10 +91,25 @@
dataType: "json",
data: $("form#EditTest").serialize(),
success: function(response) {
alert(response.successful + "\n" + response.error_message);
// Success! Updates the DOM by modifying the rows in the <table>.
if(response.successful === true) {
// Updates the meta-data
DOMelem_radio_btn_selected.attr("data-ov-subject-id", new_scheduled_subject_id);
DOMelem_radio_btn_selected.attr("data-ov-test-condition", new_scheduled_test_condition);
// Updates the visual diplay on the <td> columns.
// Error
else {
alert("Error: " + response.error_message);
// Auto-closes the pop-up edit dialog for the user.
return valid;
......@@ -127,11 +156,12 @@
// Shows the pop-up dialog with the data filled in from the record that was selected by the user.
else {
// Getters. Grabs the record data of the row selected.
var scheduled_sk = $("input[type='radio']:checked").val();
var scheduled_subject_id = $("input[type='radio']:checked").attr("data-ov-subject-id");
var scheduled_test_condition = $("input[type='radio']:checked").attr("data-ov-test-condition");
var scheduled_login_code = $("input[type='radio']:checked").attr("data-ov-login-code");
// Getters. Grabs the record data of the row selected prior to any modifications by the edit dialog.
DOMelem_radio_btn_selected = $("input[type='radio']:checked");
scheduled_sk = DOMelem_radio_btn_selected.val();
scheduled_subject_id = DOMelem_radio_btn_selected.attr("data-ov-subject-id");
scheduled_test_condition = DOMelem_radio_btn_selected.attr("data-ov-test-condition");
scheduled_login_code = DOMelem_radio_btn_selected.attr("data-ov-login-code");
// Setters. Puts the data into the pop-up dialog for the user to edit.
// Note: The 'sk' field isn't shown, but we need the data to be sent to the server nonetheless.
......@@ -140,6 +170,7 @@
// Opens the pop-up edit dialog for the user.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment