Module: AutoSessionTimeoutWarningHelper

Defined in:
lib/auto_session_timeout_warning_helper.rb

Instance Method Summary collapse

Instance Method Details

#auto_session_timeout_js(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/auto_session_timeout_warning_helper.rb', line 2

def auto_session_timeout_js(options={})
  frequency = options[:frequency] || 60
  timeout = options[:timeout] || 60
  start = options[:start] || 60
  warning = options[:warning] || 20
  code = <<JS
if(typeof(jQuery) != 'undefined'){
$("#logout_dialog").dialog({
  modal: true,
  bgiframe: true,
  width: 500,
  height: 180,
  autoOpen: false,
  dialogClass: "no-close"
});

$(".logout_dialog").click(function (e) {
  e.preventDefault();

  $("#logout_dialog").dialog('option', 'buttons', {
    "Continue": function () {
      window.location.reload();
    }
  });

  $("#logout_dialog").dialog("open");

});

function PeriodicalQuery() {
  $.ajax({
    url: '/active',
    success: function(data) {
      if(new Date(data.timeout).getTime() < (new Date().getTime() + #{warning} * 1000)){
        showDialog();
      }
      if(data.live == false){
        window.location.href = '/timeout';
      }
    }
  });
  setTimeout(PeriodicalQuery, (#{frequency} * 1000));
}
setTimeout(PeriodicalQuery, (#{start} * 1000));

function showDialog(){
  $('.logout_dialog').trigger('click');
}
}
JS
  javascript_tag(code)
end

#auto_session_warning_tag(options = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/auto_session_timeout_warning_helper.rb', line 55

def auto_session_warning_tag(options={})
  "<div id='logout_dialog' title='Logout Message' style='display:none;'>
    You are about to be logged out of this system.
    <br/><br/>
    Please click Continue if you want to stay logged in.
    </div> <div class='logout_dialog'></div>".html_safe
end