From 43748ba6c62911be97971541e742ba7e4d50031d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 20 Oct 2021 15:13:30 +0200 Subject: [PATCH] Initial version --- README.md | 7 ------- clockIn.html | 2 +- css/style.css | 13 +++---------- js/clockIn.js | 9 --------- js/index.js | 7 +++++-- js/main.js | 28 ++++++++++++++++++---------- 6 files changed, 27 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 2c4e80c..435afd5 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,3 @@ Launch application in development environment. ``` $ php -S 0.0.0.0:9090 -t . ``` - -Enable CORS on server side -``` -header('Access-Control-Allow-Origin: *'); -header("Access-Control-Allow-Headers: *"); -if($_SERVER['REQUEST_METHOD'] == "OPTIONS") die(); -``` diff --git a/clockIn.html b/clockIn.html index d1351d5..b91bdcb 100644 --- a/clockIn.html +++ b/clockIn.html @@ -67,6 +67,6 @@ and open the template in the editor. - + \ No newline at end of file diff --git a/css/style.css b/css/style.css index 29f96d8..9153950 100644 --- a/css/style.css +++ b/css/style.css @@ -284,25 +284,18 @@ header{ opacity: 1; } -.confirm{ +.confirm { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; + color: #fff; background: #8DD202; - color: #fff; } -.confirmKO{ - display: inline; - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; +.confirm.confirmKO { background: rgba(237,73,71); - color: #fff; } .contConfirm{ diff --git a/js/clockIn.js b/js/clockIn.js index 092f534..3490712 100644 --- a/js/clockIn.js +++ b/js/clockIn.js @@ -143,17 +143,8 @@ var weekDays = [ 'Sábado' ]; -function printError(msg){ - $(".txtConfirm").empty(); - $(".txtConfirm").append(msg); - $(".txtConfirm").append("
"); - $(".loading").fadeOut(200); - $(".confirm").addClass('confirmKO'); -} - function printErrores(errores) { var error =''; - $(".txtConfirm").empty(); for (var i = 0; i < errores.length; i++) { if (errores[i].error) { error += errores[i].error + "
"; diff --git a/js/index.js b/js/index.js index 89da24f..9e25ccd 100644 --- a/js/index.js +++ b/js/index.js @@ -29,16 +29,19 @@ function setEvents() { } function login() { + $(".loading").fadeIn(200); $.post({ urlPath: 'login', jsonData: [pin], processData: false, success: function (data) { localStorage.setItem("userData", JSON.stringify(data)); - $("#txtPin").text("USUARIO O DNI"); - pin = ""; window.location = "clockIn.html"; + }, + error: function() { $(".loading").fadeOut(200); + $("#txtPin").text("USUARIO"); + pin = ""; } }); diff --git a/js/main.js b/js/main.js index 10c2b42..bdf2ac7 100644 --- a/js/main.js +++ b/js/main.js @@ -1,20 +1,25 @@ var config = config[process.env.NODE_ENV]; var urlBase = config.urlBase; +function confirmReset() { + $(".confirm").removeClass('confirmKO'); + $(".txtConfirm").empty(); +} function printError(msg){ - $(".txtConfirm").empty(); + confirmReset(); $(".txtConfirm").append(msg); $(".confirm").addClass('confirmKO'); - pin = ""; - $("#txtPin").text("USUARIO"); + $(".confirm").fadeIn(200); setTimeout(function() { - $(".confirm").removeClass('confirmKO'); + $(".confirm").fadeOut(200); + setTimeout(confirmReset, 200); }, 1500); } $.ajaxPrefilter(function(xhr) { - $(".loading").fadeIn(200); + var orgErrorHandler = xhr.error; + Object.assign(xhr, { url: `${urlBase}/workerTimeControl/${xhr.urlPath}`, headers: { @@ -26,8 +31,14 @@ $.ajaxPrefilter(function(xhr) { dataType: 'json', processData: false, data: JSON.stringify(xhr.jsonData), - error: function (xhr, textStatus, err) { - var mensaje; + error: function(xhr, textStatus, err) { + if (orgErrorHandler) { + try { + orgErrorHandler(xhr, textStatus, err); + } catch (e) { + err = e; + } + } switch (textStatus){ case 'parsererror': @@ -58,9 +69,6 @@ $.ajaxPrefilter(function(xhr) { mensaje = 'Ha ocurrido un error, consulta con informática'; } printError(mensaje); - }, - complete: function() { - $(".loading").fadeOut(200); } }); });