This commit is contained in:
@@ -1,25 +1,39 @@
|
||||
|
||||
var NotificacionesADS = function () {
|
||||
var VentanaConConexion = false;
|
||||
const valueok = "1";
|
||||
function initherramientas() {
|
||||
|
||||
let nointentos = 0;
|
||||
const maxintentos = 4;
|
||||
var wNum;
|
||||
const valueok = "1";
|
||||
const AdsNotificacionesReconected = "AdsNotificacionesReconected";
|
||||
const Windownumber = "ADSWindownumber";
|
||||
const AdsNotificacionesIsConnected = "AdsNotificacionesIsConnected";
|
||||
function initherramientas() {
|
||||
if (("Notification" in window)) {
|
||||
if (Notification.permission !== 'denied') {
|
||||
Notification.requestPermission(function (permission) {
|
||||
// If the user accepts, let's create a notification
|
||||
if (permission === "granted") {
|
||||
}
|
||||
//if (permission === "granted") {
|
||||
//}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------- Eventos ----------------------------------------------------------------------
|
||||
var AlertaVentana = function (Titulo, Mensaje, Tipo, timeoutseconds,Opciones) {
|
||||
var AlertaVentana = function (Titulo, Mensaje, Tipo, timeoutseconds, Opciones) {
|
||||
console.log(Mensaje);
|
||||
let obj = { metodo: "AlertaVentana", titulo: Titulo, mensaje: Mensaje, timeout: timeoutseconds, tipo: Tipo, opciones: Opciones, tick: (new Date()).getTime() }
|
||||
let obj = { metodo: "AlertaVentana", titulo: Titulo, mensaje: Mensaje, timeout: timeoutseconds, tipo: Tipo, opciones: Opciones, tick: (new Date()).getTime() };
|
||||
let myjson = JSON.stringify(obj);
|
||||
localStorage.setItem("ADSNotificaciones", myjson);
|
||||
execAlertaVentana(obj);
|
||||
execAlertaVentana(obj);
|
||||
};
|
||||
function Execstring(script) {
|
||||
try {
|
||||
eval(script);
|
||||
} catch (e) {
|
||||
console.error('(SignalR) ErrorScript \'' + script + '\'');
|
||||
}
|
||||
}
|
||||
var execAlertaVentana = function (obj) {
|
||||
console.log(obj);
|
||||
@@ -42,7 +56,7 @@ var NotificacionesADS = function () {
|
||||
//});
|
||||
let Mensaje = obj.mensaje;
|
||||
let titulo = obj.titulo;
|
||||
let timeout = obj.timeout;
|
||||
let timeout = obj.timeout;
|
||||
if (timeout) {
|
||||
timeout = timeout * 1000;//convierto a milisegundos
|
||||
} else { timeout = 0; }
|
||||
@@ -60,7 +74,7 @@ var NotificacionesADS = function () {
|
||||
"showMethod": "fadeIn",
|
||||
"hideMethod": "fadeOut"
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
switch (obj.tipo) {
|
||||
case 5:
|
||||
@@ -79,70 +93,95 @@ var NotificacionesADS = function () {
|
||||
toastr.warning(Mensaje, titulo, opciones);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------- EndEventos ----------------------------------------------------------------------
|
||||
function closeopenConexion() {
|
||||
let varreconected = localStorage.getItem("AdsNotificacionesReconected");
|
||||
localStorage.removeItem("AdsNotificacionesIsConnected");
|
||||
if (varreconected == "1") {
|
||||
localStorage.removeItem("AdsNotificacionesReconected");
|
||||
} else { localStorage.setItem("AdsNotificacionesReconected", "1"); }
|
||||
if (VentanaConConexion) {
|
||||
localStorage.removeItem(AdsNotificacionesIsConnected);
|
||||
|
||||
let varreconected = localStorage.getItem(AdsNotificacionesReconected);//obtengo la variable para cambiarla y dispara el evento local change
|
||||
if (varreconected === "1") {
|
||||
localStorage.removeItem(AdsNotificacionesReconected);
|
||||
} else { localStorage.setItem(AdsNotificacionesReconected, "1"); }
|
||||
}
|
||||
nointentos = maxintentos;
|
||||
}
|
||||
function beforeunloadcloseopenConexion(e) {
|
||||
closeopenConexion()
|
||||
closeopenConexion();
|
||||
}
|
||||
function loadConection() {
|
||||
// VentanaConConexion = true;
|
||||
//localStorage.setItem("AdsNotificacionesIsConnected", valueok);
|
||||
//if ($.connection) {
|
||||
// let nointentos =0
|
||||
// var proxy = $.connection.notificaciones;
|
||||
// /*$.connection.hub.url = '/signalr';*/
|
||||
// $.connection.hub.disconnected(function () {
|
||||
// setTimeout(function () { nointentos = nointentos + 1; if (nointentos < 4) { $.connection.hub.start().done(function () { nointentos = 0 }); console.log('Reconected'); } }, 120000);
|
||||
// });
|
||||
function loadConection() {
|
||||
VentanaConConexion = true;
|
||||
localStorage.setItem(AdsNotificacionesIsConnected, valueok);
|
||||
if ($.connection) {
|
||||
var proxy = $.connection.notificaciones;
|
||||
/*$.connection.hub.url = '/signalr';*/
|
||||
$.connection.hub.disconnected(function () {
|
||||
console.log(' (SignalR) diconnected');
|
||||
signalrconectionStar(1200);
|
||||
});
|
||||
|
||||
// proxy.client.AlertaVentana = AlertaVentana;
|
||||
proxy.client.AlertaVentana = AlertaVentana;
|
||||
|
||||
// $.connection.hub.start().done(function () {
|
||||
// console.log('Bienvenido');
|
||||
// });
|
||||
//} else {
|
||||
// console.error('Signal Error (no se encontro $.connection)');
|
||||
proxy.client.Execstring = Execstring;
|
||||
|
||||
signalrconectionStar(1200);
|
||||
|
||||
//}
|
||||
//window.addEventListener("beforeunload", beforeunloadcloseopenConexion);
|
||||
}
|
||||
function initConnection() {
|
||||
let isconnected = localStorage.getItem("AdsNotificacionesIsConnected");
|
||||
if (isconnected == valueok) {
|
||||
} else {
|
||||
loadConection()
|
||||
console.error('(SignalR) Error :\'no se encontro $.connection\'');
|
||||
|
||||
}
|
||||
window.addEventListener("beforeunload", beforeunloadcloseopenConexion);
|
||||
}
|
||||
function signalrconectionStar(TimeOut) {
|
||||
|
||||
setTimeout(function () {
|
||||
nointentos = nointentos + 1;
|
||||
if (nointentos < maxintentos) {
|
||||
$.connection.hub.start().done(function () { console.log('(SignalR)Bienvenido'); nointentos = 0; })
|
||||
.fail(function () { console.log(' (SignalR) no conectado (Intento:' + nointentos + ')'); signalrconectionStar(12000); });
|
||||
}
|
||||
}, TimeOut);
|
||||
}
|
||||
function initConnection() {
|
||||
let isconnected = localStorage.getItem(AdsNotificacionesIsConnected);
|
||||
|
||||
|
||||
if (isconnected !== valueok) {
|
||||
loadConection();
|
||||
} else {
|
||||
console.log('is some there conected (' + wNum+')');
|
||||
}
|
||||
}
|
||||
|
||||
function handlelocalstorage() {
|
||||
function handlelocalstorage() {
|
||||
window.addEventListener('storage', function (evt) {
|
||||
if (evt.key == "ADSNotificaciones") {
|
||||
if (evt.key === "ADSNotificaciones") {
|
||||
///
|
||||
x = 1;
|
||||
}
|
||||
switch (evt.key + "") {
|
||||
case 'ADSCloseConection':
|
||||
closeopenConexion();
|
||||
$.connection.hub.stop().done(function () {
|
||||
console.log('stopped');
|
||||
});
|
||||
break;
|
||||
case 'AdsNotificacionesReconected':
|
||||
if (!VentanaConConexion) {
|
||||
setTimeout(function () { initConnection() }, 5000)
|
||||
setTimeout(function () { initConnection(); }, (wNum * 200));
|
||||
} else {
|
||||
window.removeEventListener("beforeunload", beforeunloadcloseopenConexion)
|
||||
window.removeEventListener("beforeunload", beforeunloadcloseopenConexion);
|
||||
}
|
||||
break;
|
||||
case 'ADSNotificaciones':
|
||||
try {
|
||||
let obj = JSON.parse(evt.newValue);
|
||||
if (obj && obj.metodo == "AlertaVentana") {
|
||||
if (obj && obj.metodo === "AlertaVentana") {
|
||||
execAlertaVentana(obj);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -152,6 +191,11 @@ var NotificacionesADS = function () {
|
||||
|
||||
return {
|
||||
init: function () {
|
||||
|
||||
wNum = parseInt(localStorage.getItem(Windownumber));
|
||||
if (isNaN(wNum) || (wNum > 50)) { wNum = 12; }
|
||||
wNum = wNum + 1;
|
||||
localStorage.setItem(Windownumber, wNum);
|
||||
initherramientas();
|
||||
handlelocalstorage();
|
||||
initConnection();
|
||||
|
||||
@@ -7,11 +7,11 @@ conf = {
|
||||
log: console.log,
|
||||
warn: console.warn,
|
||||
debug: console.debug
|
||||
}
|
||||
};
|
||||
console.error = function (texto) {
|
||||
loaderEnd();
|
||||
setTimeout(function () { if (Metronic && Metronic.unblockUI) { Metronic.unblockUI(); } }, 10);
|
||||
conf.error(texto);
|
||||
}
|
||||
};
|
||||
function alertatoast(tipo,Mensaje,Funcion,timeout){
|
||||
if (timeout) {
|
||||
timeout = timeout * 1000;//convierto a milisegundos
|
||||
|
||||
Reference in New Issue
Block a user