var userData = ""; $(document).ready(function () { userData = $.parseJSON(localStorage.getItem("userData")); FastClick.attach(document.body); setView(); setEvents(); }); function setEvents() { $(".btnSalir").on("click", function () { cerrar(); }); $(".in").on("click", function () { fichar('in'); }); $(".inMiddle").on("click", function () { fichar('middle'); }); $(".outMiddle").on("click", function () { fichar('middle'); }); $(".out").on("click", function () { fichar('out'); }); setTimeout(function () { cerrar(); }, 5000); } function setView() { $(".footer").hide(); $("#txtNombre").text(userData["name"] + " " + userData["surname"]); getInfo(); $("." + userData["button1"]).show(); $("." + userData["button2"]).show(); } function fichar(direction) { $.post({ urlPath: 'clockIn', jsonData: [userData['userFk'], direction], processData: false, success: function (msg) { if (msg[0].error){ printErrores(msg); setTimeout(function () { cerrar(); }, 3000); }else { $(".confirm").fadeIn(200); $(".txtConfirm").append('FICHADA REGISTRADA'); setTimeout(function () { cerrar(); }, 1000); } } }); } function setView() { $(".footer").hide(); $(".in").hide(); $(".inMiddle").hide(); $(".outMiddle").hide(); $(".out").hide(); $("#txtNombre").text(userData["name"] + " " + userData["surname"]); getInfo(); if(userData["button1"] === null && userData["button2"] === null ) { printError ("Contacta con tu resposable") } else { $("." + userData["button1"]).show(); $("." + userData["button2"]).show(); } } function getInfo() { $.post({ urlPath: 'getClockIn', jsonData: [userData['userFk']], processData: false, success: function (data) { $('.footer').show(); printHorario(data); } }); } function printHorario(horarios) { var c = "in"; for (var i = 0; i < horarios.length; i++) { if (i % 2 !== 0) { c = "out"; } else { c = "in"; } if (horarios[i]["7_dias_antes"] === "total") { if (horarios.length > (i + 1)) { printTotalHours(horarios[i + 1]); } if (horarios.length > (i + 2)) { $(".total").text('Total: ' + horarios[i + 2]["1_dia_antes"] + 'h'); } break; } $(".listHorario").append('
' + ifIsEmptyText(horarios[i]["6_dias_antes"]) + '
' + ifIsEmptyText(horarios[i]["5_dias_antes"]) + '
' + ifIsEmptyText(horarios[i]["4_dias_antes"]) + '
' + ifIsEmptyText(horarios[i]["3_dias_antes"]) + '
' + ifIsEmptyText(horarios[i]["2_dias_antes"]) + '
' + ifIsEmptyText(horarios[i]["1_dia_antes"]) + '
' + ifIsEmptyText(horarios[i]["mismo_dia"]) + '