From 8378a9d56152f0973093a53588147fa9827010a5 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 20 May 2011 11:39:44 +1200 Subject: [PATCH] MINOR Moved "pinging" logic for CMS into new LeftAndMain.Ping.js container --- admin/code/LeftAndMain.php | 2 ++ admin/javascript/LeftAndMain.Ping.js | 50 ++++++++++++++++++++++++++++ admin/javascript/LeftAndMain.js | 41 ++--------------------- 3 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 admin/javascript/LeftAndMain.Ping.js diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index 55a5e9605..7bd961fbc 100755 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -256,6 +256,7 @@ class LeftAndMain extends Controller { Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js'); Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js'); Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Tree.js'); + Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Ping.js'); Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Content.js'); Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js'); Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js'); @@ -315,6 +316,7 @@ class LeftAndMain extends Controller { SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Tree.js', + SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Ping.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Content.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js', diff --git a/admin/javascript/LeftAndMain.Ping.js b/admin/javascript/LeftAndMain.Ping.js new file mode 100644 index 000000000..f35313922 --- /dev/null +++ b/admin/javascript/LeftAndMain.Ping.js @@ -0,0 +1,50 @@ +/** + * File: LeftAndMain.EditForm.js + */ +(function($) { + $.entwine('ss', function($){ + + $('.LeftAndMain').entwine(/** @lends ss.Form_EditForm */{ + /** + * Variable: PingIntervalSeconds + * (Number) Interval in which /Security/ping will be checked for a valid login session. + */ + PingIntervalSeconds: 5*60, + + onmatch: function() { + this._super(); + + this._setupPinging(); + }, + + /** + * Function: _setupPinging + * + * This function is called by prototype when it receives notification that the user was logged out. + * It uses /Security/ping for this purpose, which should return '1' if a valid user session exists. + * It redirects back to the login form if the URL is either unreachable, or returns '0'. + */ + _setupPinging: function() { + var onSessionLost = function(xmlhttp, status) { + if(xmlhttp.status > 400 || xmlhttp.responseText == 0) { + // TODO will pile up additional alerts when left unattended + if(window.open('Security/login')) { + alert("Please log in and then try again"); + } else { + alert("Please enable pop-ups for this site"); + } + } + }; + + // setup pinging for login expiry + setInterval(function() { + jQuery.ajax({ + url: "Security/ping", + global: false, + complete: onSessionLost + }); + }, this.getPingIntervalSeconds() * 1000); + } + }); + }); +}(jQuery)); \ No newline at end of file diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 868d4606b..9576164d9 100755 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -42,12 +42,6 @@ */ $('.LeftAndMain').entwine({ - /** - * Variable: PingIntervalSeconds - * (Number) Interval in which /Security/ping will be checked for a valid login session. - */ - PingIntervalSeconds: 5*60, - /** * Constructor: onmatch */ @@ -73,45 +67,14 @@ $('body').removeClass('loading'); $(window).unbind('resize', positionLoadingSpinner); - this._setupPinging(); - $('.cms-edit-form').live('loadnewpage', function() {self.redraw()}); this._super(); }, redraw: function() { - $('.cms-content').layout(); - $('.cms-container').layout({resize: false}) - }, - - /** - * Function: _setupPinging - * - * This function is called by prototype when it receives notification that the user was logged out. - * It uses /Security/ping for this purpose, which should return '1' if a valid user session exists. - * It redirects back to the login form if the URL is either unreachable, or returns '0'. - */ - _setupPinging: function() { - var onSessionLost = function(xmlhttp, status) { - if(xmlhttp.status > 400 || xmlhttp.responseText == 0) { - // TODO will pile up additional alerts when left unattended - if(window.open('Security/login')) { - alert("Please log in and then try again"); - } else { - alert("Please enable pop-ups for this site"); - } - } - }; - - // setup pinging for login expiry - setInterval(function() { - jQuery.ajax({ - url: "Security/ping", - global: false, - complete: onSessionLost - }); - }, this.getPingIntervalSeconds() * 1000); + this.find('.cms-content').layout(); + this.find('.cms-container').layout({resize: false}) } });