$(function () { var socket = io.connect("http://localhost:4004"); socket.on('logs', function (data) { var date = new Date(data.time * 1000); var day = "0" + date.getDate(); var month = "0" + (date.getMonth() + 1); var year = date.getFullYear(); var formattedDay = day + "/" + month + "/" + year; if ($("input[name='currentDay']").val() !== formattedDay) { window.location.reload(true); } renderNewLogs(data); }); }); function openForm(e, field) { var html = ``; $(e).closest("td").html(html); } function _save(e) { $.ajax({ url: $("input[name='saveUrl']").val(), type: 'POST', data: { id: $(e).data("id"), field: $(e).data("field"), value: $(e).val() }, success: function (data) { $(e).closest("td").html(data); }, error: function (jqXHR, textStatus, errorThrown) { common.modalBlock(false); common.ajaxError(); } }); } function formatTime(unix_timestamp) { var date = new Date(unix_timestamp * 1000); var hours = date.getHours(); var minutes = "0" + date.getMinutes(); var seconds = "0" + date.getSeconds(); var day = "0" + date.getDate(); var month = "0" + (date.getMonth() + 1); var year = date.getFullYear(); var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); var formattedDay = day + "/" + month + "/" + year; return formattedTime + " " + formattedDay; } function renderNewLogs(data) { var imageIn = ""; var timeIn = ""; var imageOut = ""; var timeOut = ""; if (data.type == "in") { imageIn = ``; timeIn = formatTime(data.time); $("#totals-in").html(parseInt($("#totals-in").html()) + 1); } if (data.type == "out") { if (data.logs) { imageIn = ``; timeIn = formatTime(data.logs.time_in); } else { imageIn = ""; timeIn = ""; } imageOut = ``; timeOut = formatTime(data.time); $("#totals-out").html(parseInt($("#totals-out").html()) + 1); } var driver = data.vehicleInfo.driver.split("/"); var telephone = data.vehicleInfo.telephone.split("/"); var cmt = data.vehicleInfo.indentity_card.split("/"); var html = ` ` + data.vehicleInfo.type + ` ` + data.vehicleInfo.company + ` ` + driver.join("
") + ` ` + telephone.join("
") + ` ` + cmt.join("
") + `
không có
không có
` + data.vehicleInfo.plate + ` ` + imageIn + ` ` + timeIn + ` ` + imageOut + ` ` + timeOut + `
không có
`; $("#logs-" + data.id).remove(); $("#logs-lists").prepend(html); }