Para ello tenemos que adjuntar este codigo en el App Script en la parte final
dojo.declare("Monitor", null, {
_events: [
[window, 'scroll'],
[window, 'resize'],
[document, 'mousemove'],
[document, 'keydown']
],
_idleTime: null,
_timers: null,
idleTime: null,
constructor: function(time, timers) {
Monitor.prototype.time = time;
this._timers = timers;
this.initObservers();
this.setTimer();
},
initObservers: function() {
dojo.forEach(this._events, function(e) {
dojo.connect(e[0], e[1], function(event) {
Monitor.prototype.onInterrupt();
});
});
},
onInterrupt: function() {
this.idleTime = new Date() - this._idleTime;
dojo.publish("state:active", [this.idleTime]);
this.setTimer();
},
setTimer: function() {
var oj = Monitor.prototype;
this.clearTimers();
this._idleTime = new Date();
this._timers.push(setTimeout(function() {
dojo.publish("state:idle", null);
}, oj.time));
},
clearTimers: function() {
if (this._timers) {
for (var i = 0; i < this._timers.length; i++) {
//console.debug("Clearing Timer: " + this._timers[i]);
clearTimeout(this._timers[i]);
}
}
this._timers = [];
}
});
en nuestro main page colocamos antes de la primera linea de codigo
var logoutNow = function() {
main1.varTemplateLogout.update();
};
var logoutTimeout;
var monitor = new Monitor(180000, []); //180 000 =3 minutes
aqui lo mas importante es el valor de 180 000 corresponde a los minutos que se dispara la advertencia
ahora en nuestro main page en start event
start: function() {
dojo.addOnLoad(function() {
function onActive(args) {
monitor.clearTimers();
}
function onIdle() {
console.debug("idle...logging out");
logoutTimeout = setTimeout(logoutNow, 60000);
main.idleDialog.show();
}
dojo.subscribe("state:active", null, onActive);
dojo.subscribe("state:idle", null, onIdle);
});
},
y en nuestro main page colocamos un dialog con un label y 2 botones para que no sirva para mostrar la advertencia
idleDialog: ["wm.DesignableDialog", {"buttonBarId":"buttonBar5","containerWidgetId":"","desktopHeight":"120px","height":"120px","styles":{},"title":undefined,"width":"300px"}, {"onShow":"idleDialogShow"}, {
containerWidget16: ["wm.Container", {"_classes":{"domNode":["wmdialogcontainer","MainContent"]},"autoScroll":true,"height":"100%","horizontalAlign":"left","padding":"5","verticalAlign":"top","width":"100%"}, {}, {
label7: ["wm.Label", {"_classes":{"domNode":["dialogfooter"]},"caption":"Your session close in 60 seconds.","padding":"4","styles":{},"width":"100%"}, {}],
label4: ["wm.Label", {"caption":"Did you want to keep working?","height":"100%","padding":"4","styles":{"fontSize":"15px","fontWeight":"bold"},"width":"278px"}, {}]
}],
buttonBar5: ["wm.ButtonBarPanel", {"border":"1,0,0,0","borderColor":"#333333","desktopHeight":"33px","height":"33px"}, {}, {
YesIdleBtn: ["wm.Button", {"caption":"Yes","margin":"4","styles":{}}, {"onclick":"YesIdleBtnClick"}],
NoIdleDialog: ["wm.Button", {"caption":"No","margin":"4"}, {"onclick":"NoIdleDialogClick"}]
}]
}],
y con sus respectivos eventos
YesIdleBtnClick: function(inSender) {
clearTimeout(logoutTimeout);
monitor.clearTimers();
this.idleDialog.hide();
////execute here some query for refresh server for not go to session expiration
},
NoIdleDialogClick: function(inSender) {
main.varTemplateLogout.update();
},
idleDialogShow: function(inSender) {
try {
var downloadButton = document.getElementById("countdown");
var counter = 60;
var id
= window.setInterval(function() {
counter--;
if (counter < 0) {
clearInterval(id);
} else {
downloadButton.innerHTML = counter.toString();
}
}, 1000);
} catch (e) {
console.log(e.name, e.message);
}},
Espero que les sirva.
No hay comentarios:
Publicar un comentario