Module: AutoSessionTimeoutWarningHelper
- Defined in:
- lib/auto_session_timeout_warning_helper.rb
Instance Method Summary collapse
- #auto_session_timeout_js(options = {}) ⇒ Object
-
#auto_session_warning_tag(options = {}) ⇒ Object
Generates viewport-covering dialog HTML with message in center options={} are output to HTML.
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 54 55 56 57 58 59 60 |
# File 'lib/auto_session_timeout_warning_helper.rb', line 2 def auto_session_timeout_js(={}) frequency = [:frequency] || 60 timeout = [:timeout] || 60 start = [:start] || 60 warning = [:warning] || 20 code = "if(typeof(jQuery) != 'undefined'){\n$(\"#logout_dialog\").dialog({\n modal: true,\n width: 500,\n height: 180,\n autoOpen: false,\n dialogClass: \"no-close\"\n});\n\n$(\".logout_dialog\").click(function (e) {\n e.preventDefault();\n\n $(\"#logout_dialog\").dialog('option', 'buttons', \n [\n {\n text: \"Continue\",\n icons: {\n primary: \"ui-icon-heart\"\n },\n click: function () {\n window.location.reload();\n }\n }\n ]\n );\n\n $(\"#logout_dialog\").dialog(\"open\");\n\n});\n\nfunction PeriodicalQuery() {\n $.ajax({\n url: '/active',\n success: function(data) {\n if(new Date(data.timeout).getTime() < (new Date().getTime() + \#{warning} * 1000)){\n showDialog();\n }\n if(data.live == false){\n window.location.href = '/timeout';\n }\n }\n });\n setTimeout(PeriodicalQuery, (\#{frequency} * 1000));\n}\nsetTimeout(PeriodicalQuery, (\#{start} * 1000));\n\nfunction showDialog(){\n $('.logout_dialog').trigger('click');\n}\n}\n" javascript_tag(code) end |
#auto_session_warning_tag(options = {}) ⇒ Object
Generates viewport-covering dialog HTML with message in center
={} are output to HTML. Be CAREFUL about XSS/CSRF!
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/auto_session_timeout_warning_helper.rb', line 64 def auto_session_warning_tag(={}) = "You are about to be logged out due to inactivity.<br/><br/>Please click ‘Continue’ to stay logged in." = [:message] || warning_title = [:title] || "Logout Warning" warning_classes = !!([:classes]) ? ' class="' + [:classes] + '"' : '' # Marked .html_safe -- Passed strings are output directly to HTML! "<div id='logout_dialog' title='#{warning_title}' style='display:none;'#{warning_classes}> #{html_message} </div> <div class='logout_dialog'></div>".html_safe end |