var _dataDevices = {}; var _sending = false; var _loadingMsg = false; var _isvalid = false; var _colores = ['verde','amarillo','rojo']; $('.divLogout').hide(); function fechas(_fecha){ if(_fecha == undefined){ return "N/D"; }else{ var mili = Date.parse(_fecha); var d = new Date(mili); d = new Date(d) return d.toLocaleString(); } } function setLblLastLoad(){ $('#lblLastLoad').html(new Date(Date.now()).toLocaleString()); } function getDevices(){ $.ajax({ 'url' : '/devices', 'method' : 'POST', 'async' : 'true', 'headers':{ 'Authorization': 'Bearer ' + $('#tokenID').val() }, success: function(response){ _dataDevices = {}; var _nSelect = "Unidad"; for(var key in response){ _nSelect += '' + response[key][1]['eco'] +''; _dataDevices[response[key][0]] = { 'diasSinConexion': response[key][1]['diasSinConexion'] , 'eco': response[key][1]['eco'], 'fechaUltConexion' : response[key][1]['fechaUltConexion'], 'lat' : response[key][1]['lat'], 'lon' : response[key][1]['lon'], 'serialNumber' : response[key][1]['serialNumber'], 'ioxAddOn' : response[key][1]['ioxAddOn'] == '0' ? undefined : response[key][1]['ioxAddOn'] } } $('#unidad').html(_nSelect); $('.titPrin').html('¡Listo!'); setLblLastLoad(); }, statusCode:{ 500: function(responseError){ $('.titPrin').html(responseError['responseJSON']['error']); }, 401: function(responseError){ $('.titPrin').html('Unauthorized'); } } }); } function getPobDef(){ $.ajax({ 'url' : '/pobdef', 'method' : 'POST', 'async' : 'true', 'headers':{ 'Authorization': 'Bearer ' + $('#tokenID').val() }, success: function(response){ _poblaciones = ""; $(response).each(function(i,e){ _poblaciones += "" }); $('#puntos').html(_poblaciones); }, statusCode:{ 500: function(responseError){ $('.titPrin').html(responseError['error']); }, 401: function(responseError){ $('.titPrin').html('Unauthorized'); } } }); } function hideAll(){ $('.detail').hide(); } $('#unidad').change(function(){ changeBusHidePanels(); $('#ioxaddon').val('0'); if($(this).val() == 0 || _dataDevices[$(this).val()] == undefined){ $('.serie').html('N/D'); }else{ $('.serie').html(_dataDevices[$(this).val()]['serialNumber']); if (_dataDevices[$(this).val()]['ioxAddOn'] != undefined) $('#ioxaddon').val(_dataDevices[$(this).val()]['ioxAddOn']); } $('#msjLst').html(''); funciones(); resetPanelRst(); }); function changeBusHidePanels(){ $('.panelNvoMsj').hide(); $('.panelNvoMsjAut').hide(); $('#logReset').hide(); $('#msjLst').hide(); } function funciones(){ switch($('#ioxaddon').val()){ case "4151": $('.imgBtn').each(function(i,e){ activarFunciones(e,true); }); break; case "4096": activarFunciones('#btnRst',false); activarFunciones('#btnNewMsgAut',true); activarFunciones('#btnReloadMsg',true); activarFunciones('#btnNewMsg',true); break; default: $('.imgBtn').each(function(i,e){ activarFunciones(e,false); }); } } function activarFunciones(dato, activar){ if(activar){ $(dato).attr('src',$(dato).attr('src').replace('_desactivado.png','.png')); }else if (!$(dato).attr('src').includes('_desactivado.png')){ $(dato).attr('src',$(dato).attr('src').replace('.png','_desactivado.png')); } } $('#btnShowMap').click(function(){ if ($('#unidad').val() == 0 || _dataDevices[$('#unidad').val()]['lat'] == undefined || _dataDevices[$('#unidad').val()]['lon'] == undefined){ alert('Ubicación NO DISPONIBLE'); }else{ window.open('https://www.google.com/maps/search/'+ _dataDevices[$('#unidad').val()]['lat'] +',+'+ _dataDevices[$('#unidad').val()]['lon'] +'/@'+ _dataDevices[$('#unidad').val()]['lat'] +','+ _dataDevices[$('#unidad').val()]['lon'] +',17z','_blank'); } }); $('#btnNewMsg').click(function(){ if(!$(this).attr('src').includes('desactivado')) { $('.panelNvoMsj').show(); $('.panelNvoMsjAut').hide(); $('#logReset').hide(); $('#msjLst').show(); } }); $('#btnNewMsgAut').click(function(){ if(!$(this).attr('src').includes('desactivado')) { $('.panelNvoMsjAut').show(); $('.panelNvoMsj').hide(); $('#logReset').hide(); $('#msjLst').hide(); } }); $('#btnRst').click(function(){ if(!$(this).attr('src').includes('desactivado')) { $('.panelNvoMsjAut').hide(); $('.panelNvoMsj').hide(); $('#logReset').show(); $('#msjLst').hide(); } }); $('#btnReloadMsg').click(function(){ if (!_loadingMsg && !$(this).attr('src').includes('desactivado')){ if( $('#unidad').val() == 0 ){ alert('Elija una unidad'); }else{ _loadingMsg=true; $('.panelNvoMsjAut').hide(); $('#logReset').hide(); $('.titPrin').html('Cargando...'); $.ajax({ 'url' : '/info', 'method' : 'POST', 'async' : 'true', 'headers':{ 'Authorization': 'Bearer ' + $('#tokenID').val() }, 'data' : $('#f1').serialize(), success: function(response){ var _nListaMensajes = ""; $(response).each(function(i,e){ _nListaMensajes += ''+e[1].msj +''+ fechas(e[1].enviado) +''+ fechas(e[1].entregado) +''; }); $('#msjLst').html(_nListaMensajes); $('#msjLst').show(); $('.titPrin').html('¡Listo!'); $('.listaDivItemMsj').each(function(){ $(this).click(function(){ $(this).children('.detMsg').toggle(); if($(this).children('.detMsg').css('display') == "none"){ $(this).css('height','40px'); }else{ $(this).css('height','90px'); } }); }); _loadingMsg = false; setLblLastLoad(); }, statusCode:{ 500: function(responseError){ $('.titPrin').html(responseError['responseJSON']['error']); $('#msjLst').html(''); _loadingMsg = false; }, 401: function(responseError){ $('.titPrin').html('Unauthorized'); $('#msjLst').html(''); _loadingMsg = false; } } }); } } }); $('#send').click(function(){ if( !_sending){ if( $('#unidad').val() == 0 ){ alert('Elija una unidad'); }else if($('#nMensaje').val().length <= 0){ alert('Por favor escriba un mensaje'); }else if($('#nMensaje').val().length > 50){ alert('Mensaje máximo 50 caracteres') }else{ _sending = true; $('.titPrin').html('Enviando...'); $.ajax({ 'url' : '/newMsj', 'method' : 'POST', 'async' : 'true', 'headers':{ 'Authorization': 'Bearer ' + $('#tokenID').val() }, 'data' : $('#f1').serialize(), success: function(response){ if( response['result'] != undefined){ $('.titPrin').html('¡Listo!'); $('.panelNvoMsj').hide(); $('#nMensaje').val(''); _sending = false; setLblLastLoad(); } },statusCode:{ 500: function(responseError){ $('.titPrin').html(responseError['responseJSON']['error']); _sending = false; }, 401: function(responseError){ $('.titPrin').html('Unauthorized'); _sending = false; } } }); } } }); $('.imgBtnAut').click(function(){ valorActual = $(this).attr('src').indexOf('_') < 0 ? 'verde' : $(this).attr('src').substring($(this).attr('src').indexOf('_')+1,$(this).attr('src').indexOf('.')); nuevo = (_colores.findIndex(x => x == valorActual) + 1) < _colores.length ? (_colores.findIndex(x => x == valorActual) + 1) : 0; $(this).attr('src', $(this).attr('src').substring(0,$(this).attr('src').indexOf('_')+1) + _colores[nuevo] + '.png' ); calcularAut(); }); function calcularAut(){ $('#fAtras').val($('#imgfAtras').attr('src').includes('verde') ? 10 : ($('#imgfAtras').attr('src').includes('amarillo') ? 14 : 15) ); $('#fAdela').val($('#imgfAdela').attr('src').includes('verde') ? 10 : ($('#imgfAdela').attr('src').includes('amarillo') ? 14 : 15) ); $('#punt').val($('#imgpunt').attr('src').includes('verde') ? 0 : ($('#imgpunt').attr('src').includes('amarillo') ? 4 : 5) ); } $('#sendAut').click(function(){ if( !_sending){ if( $('#unidad').val() == 0 ){ alert('Elija una unidad'); }else if($('#origen').val().length <= 0 || $('#destino').val().length <= 0){ alert('Por favor escriba un origen/destino'); }else if($('#origen').val().length > 3 || $('#destino').val().length > 3){ alert('El origen/destino solo pueden ser de 3 caracteres'); }else if($('#datestart').val() == undefined || $('#datestart').val().length <= 0 ){ alert('Establezca la Fecha/Hora del viaje'); }else{ _sending = true; $('.titPrin').html('Enviando...'); $.ajax({ 'url' : '/sendMsgAut', 'method' : 'POST', 'async' : 'true', 'headers':{ 'Authorization': 'Bearer ' + $('#tokenID').val() }, 'data' : $('#f1').serialize(), success: function(response){ _sending = false; if( response['result'] != undefined){ $('.titPrin').html('Enviado!'); setTimeout(function(){ $('.titPrin').html('¡Listo!'); },1500) setLblLastLoad(); } },statusCode:{ 500: function(responseError){ _sending = false; $('.titPrin').html(responseError['responseJSON']['error']); }, 401: function(responseError){ $('.titPrin').html('Unauthorized'); _sending = false; } } }); } } }); $('#cancel').click(function(){ $('.panelNvoMsj').hide(); $('#nMensaje').val(''); }); $('#cancelAut').click(function(){ $('.panelNvoMsjAut').hide(); }); $('#imgBtnRst').click(function(){ if( !_sending){ if( $('#unidad').val() == 0 ){ alert('Elija una unidad'); }else{ _sending = true; hideChkListRst(); $('#loader').show(); $('#sender').hide(); $('.divLogout').hide(); $('.titPrin').html('Intentando reinicio...'); $.ajax({ 'url' : '/sendRst', 'method' : 'POST', 'async' : 'false', 'headers':{ 'Authorization': 'Bearer ' + $('#tokenID').val() }, 'data' : $('#unidad').serialize(), success: function(response){ _sending = false; setLblLastLoad(); $('.titPrin').html('¡Listo!'); $('#imgBtnRst').attr('src','/static/img/btn_reenviar.png'); for(i=1; i<=5;i++){ id = "#imgp" + i; $(id).attr('src','/static/img/paso_' + (response['paso'] >= i ? 'ok':'fallo') + '.png'); } $('.cklstRst').show(); $('#loader').hide(); $('#sender').show(); $('.divLogout').show(); },statusCode:{ 500: function(responseError){ $('.titPrin').html(responseError['error']); _sending = false; $('#imgBtnRst').attr('src','/static/img/btn_reenviar.png'); $('#loader').hide(); $('#sender').show(); $('.divLogout').show(); }, 404: function(responseError){ $('.titPrin').html('404'); _sending = false; $('#imgBtnRst').attr('src','/static/img/btn_reenviar.png'); $('#loader').hide(); $('#sender').show(); $('.divLogout').show(); }, 401: function(responseError){ $('.titPrin').html('Unauthorized'); _sending = false; $('#imgBtnRst').attr('src','/static/img/btn_reenviar.png'); $('#loader').hide(); $('#sender').show(); $('.divLogout').show(); } } }); } } }); function hideChkListRst(){ $('.cklstRst').each(function(){ $(this).hide(); }); } function resetPanelRst(){ hideChkListRst(); $('#imgBtnRst').attr('src','/static/img/btn_iniciar.png'); } function iniciar(){ getDevices(); setAutVal(); getPobDef(); $('#sender').show(); } function setAutVal(){ $('#datestart').val(Date.now()); }
'+e[1].msj +'
'+ fechas(e[1].enviado) +'
'+ fechas(e[1].entregado) +'