| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- $(function() {
- initialiseBeforeTestForm();
- initialiseTestForm();
- });
- var durationInterval = false;
- var testStartTime = null;
- function initialiseBeforeTestForm() {
- $("#before-test-form").on("submit", function() {
- $(this).find("button").prepend("<i class=\"fas fa-pulse fa-spinner\"></i> ").attr("disabled", "");
- $(this).find("div[data-submitting-div]").removeClass("d-none");
- });
- }
- function initialiseTestForm() {
- const $form = $("#test-form");
- 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);
- };
- $form.on("submit", function(event) {
- event.preventDefault();
- showAlert("alert-info", "fa-sync", "Submitting...", "Please wait...");
- $submitButton.prop("disabled", true);
- const formData = new FormData($form.get(0));
- $.ajax({
- type: "post",
- url: window.location,
- data: formData,
- processData: false,
- contentType: false,
- async: false,
- cache: false,
- success: (response) => {
- try {
- 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.");
- setTimeout(function() {
- window.location = "/account/tests";
- }, 3000);
- }
- catch(err) {
- showAlert("alert-danger", "fa-exclamation-circle", "Error", err);
- $submitButton.prop("disabled", false);
- }
- },
- error: function(request, status, error) {
- console.log(request, status, error);
- showAlert("alert-danger", "fa-exclamation-circle", "No Internet Connectivity", "Please check your Internet connectivity and try again.");
- $submitButton.prop("disabled", false);
- }
- });
- });
- }
|