let userData = ""; $(document).ready(function () { userData = JSON.parse(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) { const data = { workerFk: userData['userFk'], direction, device: localStorage.getItem("device") } $.post({ urlPath: 'WorkerTimeControls/clockIn', jsonData: data, processData: false, success: function (msg) { if (msg.error){ printErrores(msg); setTimeout(function () { cerrar(); }, 2000); }else { $(".confirm").fadeIn(200); $(".txtConfirm").append('Fichada registrada correctamente'); 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 responsable") } else { $("." + userData["button1"]).show(); $("." + userData["button2"]).show(); } } function getInfo() { const queryString = $.param({ workerFk: userData['userFk'] }); $.get({ urlPath: `WorkerTimeControls/getClockIn?${queryString}`, processData: false, success: function (data) { $('.footer').show(); printTimetable(data); } }); } function printTimetable(timetable) { const listWeekName = [ 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado' ];; let dated = new Date(); dated.setDate(dated.getDate() - 6); for (let i = 0; i < 6; i++) { $(".listHorario").append(''); dated.setDate(dated.getDate() + 1); } $(".listHorario").append(''); $(".listHorario").append('
'); for (let i = 0; i < timetable.length; i++) { $(".listHorario").append( '