Skip to content

Instantly share code, notes, and snippets.

@hakanak
Created May 23, 2019 06:57
Show Gist options
  • Save hakanak/05d0e59da69f107ae6a9da5af6a5d31d to your computer and use it in GitHub Desktop.
Save hakanak/05d0e59da69f107ae6a9da5af6a5d31d to your computer and use it in GitHub Desktop.
var siteRoot = 'https://demo.com/'
var warningTime = '1'
function callSessionRefreshWebService()
{
jQuery.ajax({
type: "POST",
contenttype: "application/json; charset=utf-8",
data: "{}",
url: siteRoot + "WEbservices/SessionRefresh.asmx/Refresh",
dataTyp:"json",
success: function(res) {
SessionTimeoutCounter.CounterReset();
},
error: function(err) {
// alert("hata");
}
});
};
function ShowTimeoutPopup(){
swal({
title: 'UYARI',
text: '29 dakikadır uygulamada işlem gerçekleştirmediniz. Oturumunuz zaman aşımına uğramak üzeredir. İşleme kaldığınız yerden devam etmek için "Devam Et" butonuna basınız.',
type: "info",
showCancelButton: false,
confirmButtonText: "Devam Et",
showLoaderOnConfirm: true
}).then (function (){SessionTimeout.sendKeepAlive();});
}
window.SessionTimeout = (function() {
var _timeLeft, _popupTimer, _countDownTimer;
var stopTimers = function() {
window.clearTimeout(_popupTimer);
window.clearTimeout(_countDownTimer);
};
var updateCountDown = function() {
var min = Math.floor(_timeLeft / 60);
var sec = _timeLeft % 60;
if(sec < 10)
sec = "0" + sec;
if(_timeLeft > 0) {
_timeLeft--;
_countDownTimer = window.setTimeout(updateCountDown, 1000);
} else {
document.location = "Login.aspx";
}
};
var showPopup = function() {
window.focus();
_timeLeft = parseFloat(warningTime)*60;
updateCountDown();
ShowTimeoutPopup();
};
var schedulePopup = function() {
stopTimers();
_popupTimer = window.setTimeout(showPopup, 1740000);
};
var sendKeepAlive = function() {
stopTimers();
callSessionRefreshWebService();
schedulePopup();
};
return {
schedulePopup: schedulePopup,
sendKeepAlive: sendKeepAlive
};
})();
window.SessionTimeoutCounter = (function() {
var _timeLeft, _countDownTimer, _sessionTimeout;
var setTimer = function(timer){
_timeLeft = timer;
_sessionTimeout = timer;
};
var counterReset = function(){
_timeLeft = _sessionTimeout;
}
var updateCountDown = function(timerid) {
var min = Math.floor(_timeLeft / 60);
var sec = _timeLeft % 60;
if(sec < 10)
sec = "0" + sec;
document.getElementById(timerid).innerHTML = min + ":" + sec;
if(_timeLeft > 0) {
_timeLeft--;
if( (_timeLeft % (_sessionTimeout/100) ) == 0)
counterPercentEvent((_timeLeft / _sessionTimeout) * 100);
_countDownTimer = window.setTimeout(function(){updateCountDown(timerid)}, 1000);
} else {
document.location = "Login.aspx";
}
};
var counterPercentEvent = function(percent){
var obj = jQuery(".progress-bar")
obj.attr("aria-valuenow", percent);
obj.css("width", percent + "%");
};
return {
SetTimer: setTimer,
UpdateCountDown: updateCountDown,
CounterPercentEvent : counterPercentEvent,
CounterReset : counterReset
};
})();
SessionTimeoutCounter.SetTimer(1800);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment