Forráskód Böngészése

Adjust appearance of test submit status

Alan Lam 2 éve
szülő
commit
3d18b4eb3a

+ 8 - 8
engine/template.php

@@ -326,14 +326,14 @@ class Template extends Model {
 					</button>
 				</div>
 
-				<div class="text-center">
-					<small class="form-text text-muted d-none" id="test-no-internet-text">
-						<span class="text-danger"><?=htmlspecialchars(__("No Internet Connectivity"))?></span><br />
-						<?=htmlspecialchars(__("Please check your Internet connectivity and try again."))?>
-					</small>
-					<small id="test-submit-status">
-
-					</small>
+				<div id="test-submit-alert" class="alert" hidden>
+					<div class="mb-1">
+						<i class="fa fa-fw fa-info-circle"></i> <strong></strong>
+					</div>
+
+					<div id="test-submit-status">
+
+					</div>
 				</div>
 
 			</div>

+ 39 - 28
public/js/app-practice-test.js

@@ -17,19 +17,34 @@ function initialiseBeforeTestForm() {
 
 function initialiseTestForm() {
 
-	$form = $("#test-form");
+	const $form = $("#test-form");
 
-	$stopButtonContainer = $("#test-stop-button-container");
+	const $stopButtonContainer = $("#test-stop-button-container");
 
-	$startButton = $("#test-start-button");
-	$stopButton = $("#test-stop-button");
+	const $startButton = $("#test-start-button");
+	const $stopButton = $("#test-stop-button");
 
-	$testMainFormContainer = $("#test-main-form-container");
-	$submitButton = $("#test-submit-button");
+	const $testMainFormContainer = $("#test-main-form-container");
 
-	$noInternetText = $("#test-no-internet-text");
+	const $submitButton = $("#test-submit-button");
+
+	const $alert = $("#test-submit-alert");
+	const $alertIcon = $alert.find(".fa");
+	const $alertHeading = $alert.find("strong");
+	const $alertText = $("#test-submit-status");
+
+	const showAlert = (alertClass, icon, heading, text) => {
+		$alert.prop("hidden", false);
+		$alert.attr("class", `alert ${alertClass}`);
+		$alertIcon.attr("class", `fa fa-fw ${icon}`);
+		$alertHeading.text(heading);
+		$alertText.text(text);
+	};
+
+	const hideAlert = () => {
+		$alert.prop("hidden", true);
+	};
 
-	$submitStatus = $("#test-submit-status");
 
 	$startButton.on("click", function(event) {
 		event.preventDefault();
@@ -66,12 +81,11 @@ function initialiseTestForm() {
 
 
 	$form.on("submit", function(event) {
-
 		event.preventDefault();
 
-		$noInternetText.addClass("d-none");
-		$submitStatus.html("Submitting...");
-		$submitButton.attr("disabled", "");
+		showAlert("alert-info", "fa-sync", "Submitting...", "Please wait...");
+
+		$submitButton.prop("disabled", true);
 
 		const formData = new FormData($form.get(0));
 
@@ -83,33 +97,30 @@ function initialiseTestForm() {
 			contentType: false,
 			async: false,
 			cache: false,
-			success: function(data, text) {
-
+			success: function(response, text) {
 				try {
-					if(!data.success) throw "Unsuccessful.";
+					if(!response.success && response.message) {
+						throw response.message;
+					}
+					else if(!response.success) {
+						throw "Please try again later.";
+					}
+
+					showAlert("alert-success", "fa-check", "Submit Successful", "Thank you for participating in this test. You will be redirected to the Tests page in three seconds.");
 
-					$submitStatus.html("Submitted. Thank you for participating in this test. You will be redirected in three seconds.");
 					setTimeout(function() {
 						window.location = window.location;
 					}, 3000);
 				}
 				catch(err) {
-
-					if(data.message) {
-						$submitStatus.html("Error: " + data.message.replace("\n", "<br />"));
-					}
-					else {
-						$submitStatus.html("Error, please try again later.");
-					}
-
-					$submitButton.removeAttr("disabled");
+					showAlert("alert-danger", "fa-exclamation-circle", "Error", err);
+					$submitButton.prop("disabled", false);
 				}
 			},
 			error: function(request, status, error) {
 				console.log(request, status, error);
-				$submitStatus.html("");
-				$noInternetText.removeClass("d-none");
-				$submitButton.removeAttr("disabled");
+				showAlert("alert-danger", "fa-exclamation-circle", "No Internet Connectivity", "Please check your Internet connectivity and try again.");
+				$submitButton.prop("disabled", false);
 			}
 		});
 

+ 26 - 13
public/js/app-test.js

@@ -16,23 +16,32 @@ function initialiseBeforeTestForm() {
 }
 
 function initialiseTestForm() {
-
 	const $form = $("#test-form");
 
-	const $testMainFormContainer = $("#test-main-form-container");
-
 	const $submitButton = $("#test-submit-button");
 
-	const $noInternetText = $("#test-no-internet-text");
+	const $alert = $("#test-submit-alert");
+	const $alertIcon = $alert.find(".fa");
+	const $alertHeading = $alert.find("strong");
+	const $alertText = $("#test-submit-status");
 
-	const $submitStatus = $("#test-submit-status");
+	const showAlert = (alertClass, icon, heading, text) => {
+		$alert.prop("hidden", false);
+		$alert.attr("class", `alert ${alertClass}`);
+		$alertIcon.attr("class", `fa fa-fw ${icon}`);
+		$alertHeading.text(heading);
+		$alertText.text(text);
+	};
+
+	const hideAlert = () => {
+		$alert.prop("hidden", true);
+	};
 
 	$form.on("submit", function(event) {
 
 		event.preventDefault();
 
-		$noInternetText.addClass("d-none");
-		$submitStatus.html("Submitting...");
+		showAlert("alert-info", "fa-sync", "Submitting...", "Please wait...");
 
 		$submitButton.prop("disabled", true);
 
@@ -48,23 +57,27 @@ function initialiseTestForm() {
 			cache: false,
 			success: (response) => {
 				try {
-					if(!response.success && response.message) throw response.message;
-					else if(!response.success) throw "Please try again later.";
+					if(!response.success && response.message) {
+						throw response.message;
+					}
+					else if(!response.success) {
+						throw "Please try again later.";
+					}
+
+					showAlert("alert-success", "fa-check", "Submit Successful", "Thank you for participating in this test. You will be redirected to the Tests page in three seconds.");
 
-					$submitStatus.html("Submitted. Thank you for participating in this test. You will be redirected to the Tests page in three seconds.");
 					setTimeout(function() {
 						window.location = "/account/tests";
 					}, 3000);
 				}
 				catch(err) {
-					$submitStatus.html("Error: " + err);
+					showAlert("alert-danger", "fa-exclamation-circle", "Error", err);
 					$submitButton.prop("disabled", false);
 				}
 			},
 			error: function(request, status, error) {
 				console.log(request, status, error);
-				$submitStatus.html("");
-				$noInternetText.removeClass("d-none");
+				showAlert("alert-danger", "fa-exclamation-circle", "No Internet Connectivity", "Please check your Internet connectivity and try again.");
 				$submitButton.prop("disabled", false);
 			}
 		});

+ 1 - 1
template_processing/age_verification_greene_king/test_validate.php

@@ -60,7 +60,7 @@ if($test->dts_start && $test->dts_end) {
 			}
 
 			if($dt_bar < $dt_bar_min || $dt_bar > $dt_end) {
-				$form_exception->addError("Bar arrival time must be between $min_bar_time and $end_time.");
+				$form_exception->addError("Bar arrival time must be on or after $min_bar_time.");
 			}
 		}
 	}

+ 7 - 7
views/test_form.php

@@ -50,14 +50,14 @@ else if($test->isPendingVerification()) {
 			</button>
 		</div>
 
-		<div class="text-center">
-			<small class="form-text text-muted d-none" id="test-no-internet-text">
-				<span class="text-danger"><?=htmlspecialchars(__("No Internet Connectivity"))?></span><br />
-				<?=htmlspecialchars(__("Please check your Internet connectivity and try again."))?>
-			</small>
-			<small id="test-submit-status">
+		<div id="test-submit-alert" class="alert" hidden>
+			<div class="mb-1">
+				<i class="fa fa-fw fa-info-circle"></i> <strong></strong>
+			</div>
 
-			</small>
+			<div id="test-submit-status">
+
+			</div>
 		</div>
 
 	</form>