"use strict"; // Class definition var KTSignInGeneral = function () { // Elements var form; var submitButton; var validator; // Handle form var handleForm = function (e) { // Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/ validator = FormValidation.formValidation( form, { fields: { _u: { validators: { notEmpty: { message: language[iso].username_invalid, } } }, _p: { validators: { notEmpty: { message: language[iso].password_invalid, } } } }, plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap: new FormValidation.plugins.Bootstrap5({ rowSelector: '.fv-row' }) } } ); // Handle form submit submitButton.addEventListener('click', function (e) { // Prevent button default action e.preventDefault(); // Validate form validator.validate().then(function (status) { if (status == 'Valid') { // Show loading indication submitButton.setAttribute('data-kt-indicator', 'on'); // Disable button to avoid multiple click submitButton.disabled = true; // Simulate ajax request setTimeout(function () { // Ajax Run var options = {}; options.url = admin_base_url+"login/submit/"; options.method = "POST"; options.dataType = "json"; options.timeout = timeout; options.contentType = false; options.cache = false; options.processData = false; options.data = new FormData(form); $.ajax(options).then( function (data) { // Hide loading indication submitButton.removeAttribute('data-kt-indicator'); // Enable button submitButton.disabled = false; if (data.code === 100) { // Show message popup. For more info check the plugin's official documentation: https://sweetalert2.github.io/ Swal.fire({ text: data.message, icon: "success", buttonsStyling: false, confirmButtonText: language[iso].ok, customClass: { confirmButton: "btn btn-primary" } }); setTimeout(function () { window.location.href = admin_base_url+'dashboard/'; }, redirect); } else if (data.code === 800) { Swal.fire({ text: data.message, icon: "error", buttonsStyling: false, confirmButtonText: language[iso].ok, customClass: { confirmButton: "btn btn-primary" } }); setTimeout(function () { location.reload(); }, redirect); } else { validator.resetForm(); Swal.fire({ text: data.message, icon: "error", buttonsStyling: false, confirmButtonText: language[iso].ok, customClass: { confirmButton: "btn btn-primary" } }); setTimeout(function () { window.location.reload(); }, redirect); } } ).catch(function (e) { // Hide loading indication submitButton.removeAttribute('data-kt-indicator'); // Enable button submitButton.disabled = false; Swal.fire({ text: language[iso].timeout_title, icon: "info", buttonsStyling: false, confirmButtonText: language[iso].try_again, customClass: { confirmButton: "btn btn-primary" } }); setTimeout(function () { window.location.reload(); }, redirect); }); }, ajax); } else { // Show error popup. For more info check the plugin's official documentation: https://sweetalert2.github.io/ Swal.fire({ text: language[iso].form_message, icon: "error", buttonsStyling: false, confirmButtonText: language[iso].ok, customClass: { confirmButton: "btn btn-primary" } }); } }); }); } // Public functions return { // Initialization init: function () { form = document.querySelector('#kt_sign_in_form'); submitButton = document.querySelector('#kt_sign_in_submit'); handleForm(); } }; }(); // On document ready KTUtil.onDOMContentLoaded(function () { KTSignInGeneral.init(); });