Advertisement
brlombar

InactivitySignOutPanel.js

May 27th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Wicket.SignOut = function(timeout, url) {
  2.     this.timeout = timeout; // Timeout in miliseconds.
  3.     this.url = url;
  4.     // Add timeout (in seconds) to current time to get absolute timeout time.
  5.     this.timeoutTime  = new Date();
  6.     this.timeoutTime.setSeconds(this.timeoutTime.getSeconds() + this.timeout / 1000);
  7.     this.init();
  8. };
  9.  
  10. Wicket.SignOut.prototype.init = function() {
  11.     var self = this;
  12.     Wicket.Event.subscribe('/ajax/call/before', function(jqEvent, attributes, jqXHR, errorThrown, textStatus) {
  13.         self.reset();
  14.     });
  15.  
  16.     Wicket.Event.subscribe('/ajax/call/after', function(jqEvent, attributes, jqXHR, errorThrown, textStatus) {
  17.         self.reset();
  18.     });
  19.     this.reset();
  20.     // Set interval to one quarter of the timeout time.
  21.     var interval = this.timeout / 4;
  22.     // console.log("interval", interval);
  23.     setInterval(function(){self.countDown();}, interval);
  24. };
  25.  
  26. Wicket.SignOut.prototype.reset = function() {
  27.     // console.log("Reset Called");
  28.     this.timeoutTime  = new Date();
  29.     this.timeoutTime.setSeconds(this.timeoutTime.getSeconds() + this.timeout / 1000);
  30. };
  31.  
  32. Wicket.SignOut.prototype.countDown = function() {
  33.     now = new Date();
  34.     // console.log("Countdown Called");
  35.     // console.log("now, timeoutTime", now, this.timeoutTime);
  36.     if (now > this.timeoutTime){
  37.         //trigger the server side sign out
  38.         Wicket.Ajax.get({"u": this.url});
  39.     }
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement