Skip to content

Instantly share code, notes, and snippets.

@rmdort
Last active November 30, 2015 09:01
Show Gist options
  • Select an option

  • Save rmdort/5d3c186bfb0f8b4ceb20 to your computer and use it in GitHub Desktop.

Select an option

Save rmdort/5d3c186bfb0f8b4ceb20 to your computer and use it in GitHub Desktop.

Open session Modal

MOM.modal.openSessionModal(options);

Options

title: 'Your session is about to expire',
message: 'You will be logged out in <strong>{time}</strong> seconds. Do you want to stay logged in?',
confirm_action: 'javascript:fnConfirmSessionExtend()',
cancel_action: 'javascript:void(0)',
confirm_button_title: 'Yes, keep me signed in',
cancel_button_title: 'No, Sign me out'

Close session Modal

MOM.modal.closeSessionModal()

Update session Modal

MOM.modal.updateSessionModal(time)

Example to open modal

MOM.modal.openSessionModal({
    title: 'Hey session expiring',
    message: 'Expiring in {time}'
    confirm_action: 'javascript:fnConfirmSessionExtend()',
    cancel_action: 'javascript:void(0)',
    confirm_button_title: 'Yes continue session',
    cancel_button_title: 'Cancel'
})

Example to update modal

MOM.modal.updateSessionModal(60)

// You have to use setInterval and call this function to update the time

var sessionInterval = setInterval( function(){ 
    MOM.modal.updateSessionModal(30)
}, 1000)

// Clear the interval and close the modal once done

clearInterval(sessionInterval)

MOM.modal.closeSessionModal();
var timer;
var countDownStart = 60; /* Seconds */
function openSessionModal(){
MOM.modal.openSessionModal({
confirm_action: 'javascript:onContinueSession()',
cancel_action: 'javascript:onCancelSession()',
time: countDownStart
});
var currentTime = new Date().getTime();
timer = setInterval(function(){
var now = new Date().getTime();
var diff = now - currentTime;
var seconds = countDownStart - Math.floor(diff / 1000);
if(seconds == 0){
clearInterval(timer);
onCancelSession();
}
MOM.modal.updateSessionModal(seconds);
}, 1000)
}
/* Continue session */
function onContinueSession(){
console.log('continue session => DO ANYTHING HERE')
}
/* Cancel session */
function onCancelSession(){
console.log('cancel session => DO REDIRECT')
}
function checkBackendSession(){
/* Check the server of session using $.get */
var isSessionExpiring = true;
if(isSessionExpiring) openSessionModal();
}
window.setTimeout(checkBackendSession,1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment