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(); $("." + 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"]) + '

  • '); } var listWeekName = printWeek(); $(".listHorario").prepend('
  • '); } function printTotalHours(horarios) { $(".listHorario").append('


  • '); $(".listHorario").append('
  • ' + ifIsEmptyText(horarios["6_dias_antes"]) + '
    ' + ifIsEmptyText(horarios["5_dias_antes"]) + '
    ' + ifIsEmptyText(horarios["4_dias_antes"]) + '
    ' + ifIsEmptyText(horarios["3_dias_antes"]) + '
    ' + ifIsEmptyText(horarios["2_dias_antes"]) + '
    ' + ifIsEmptyText(horarios["1_dia_antes"]) + '
    ' + ifIsEmptyText(horarios["mismo_dia"]) + '
  • '); } function printWeek() { var listWeekName = []; var curr = new Date(); for (var i = 0; i < 7; i++) { curr.setDate(curr.getDate() - 1); listWeekName.push(weekDays[curr.getDay()]); } return listWeekName; } var weekDays = [ 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', '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 + "
    "; } } printError(error); } function ifIsEmpty(value) { if (value.trim().length === 0) { return "hide"; } else { return "show"; } } function ifIsEmptyText(value) { if (value.trim().length === 0) { return "00:00"; } else { return value; } } function cerrar(){ $(".loading").fadeIn(200); localStorage.removeItem("userData"); setTimeout(function () { window.history.back(); }, 200); }