Skip to content

Instantly share code, notes, and snippets.

@nickcoyne
Last active February 23, 2017 01:21
Show Gist options
  • Save nickcoyne/1d9d052824978363b66eba4a5922c64b to your computer and use it in GitHub Desktop.
Save nickcoyne/1d9d052824978363b66eba4a5922c64b to your computer and use it in GitHub Desktop.
class @App.Components.TempUserTimer
constructor: ->
@timeoutWarning = 10000 # Display warning in 1 min.
@timeoutNow = 60000 # Warning has been shown, give the user 1 minute to interact
@logoutUrl = '/timeout' # URL to logout page.
# Button click handlers
# close page
$(document).on 'click', '.js-temp-user-logout', =>
@timeout()
# continue
$(document).on 'click', '.js-temp-user-continue', =>
@reset()
console.log 'constructed'
# Logout the user
timeout: ->
console.log 'timeout'
window.location = @logoutUrl
# Show idle timeout warning dialog.
warning: ->
console.log 'warning'
clearTimeout @warningTimer
@timeoutTimer = setTimeout (=>
@timeout()
), @timeoutNow
BetterModals.showModal $('#modalLogoutWarning')
# Start warning timer.
start: ->
console.log 'start'
@warningTimer = setTimeout (=>
@warning()
), @timeoutWarning
# Reset timers.
reset: ->
console.log 'reset'
clearTimeout @timeoutTimer
@start()
BetterModals.closeModal $('#modalLogoutWarning')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment