mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Moved "pinging" logic for CMS into new LeftAndMain.Ping.js container
This commit is contained in:
parent
4e0949f565
commit
8378a9d561
@ -256,6 +256,7 @@ class LeftAndMain extends Controller {
|
|||||||
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js');
|
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js');
|
||||||
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.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.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.Content.js');
|
||||||
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js');
|
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js');
|
||||||
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.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.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js',
|
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Tree.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.Content.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js',
|
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js',
|
SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js',
|
||||||
|
50
admin/javascript/LeftAndMain.Ping.js
Normal file
50
admin/javascript/LeftAndMain.Ping.js
Normal file
@ -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));
|
@ -42,12 +42,6 @@
|
|||||||
*/
|
*/
|
||||||
$('.LeftAndMain').entwine({
|
$('.LeftAndMain').entwine({
|
||||||
|
|
||||||
/**
|
|
||||||
* Variable: PingIntervalSeconds
|
|
||||||
* (Number) Interval in which /Security/ping will be checked for a valid login session.
|
|
||||||
*/
|
|
||||||
PingIntervalSeconds: 5*60,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: onmatch
|
* Constructor: onmatch
|
||||||
*/
|
*/
|
||||||
@ -73,45 +67,14 @@
|
|||||||
$('body').removeClass('loading');
|
$('body').removeClass('loading');
|
||||||
$(window).unbind('resize', positionLoadingSpinner);
|
$(window).unbind('resize', positionLoadingSpinner);
|
||||||
|
|
||||||
this._setupPinging();
|
|
||||||
|
|
||||||
$('.cms-edit-form').live('loadnewpage', function() {self.redraw()});
|
$('.cms-edit-form').live('loadnewpage', function() {self.redraw()});
|
||||||
|
|
||||||
this._super();
|
this._super();
|
||||||
},
|
},
|
||||||
|
|
||||||
redraw: function() {
|
redraw: function() {
|
||||||
$('.cms-content').layout();
|
this.find('.cms-content').layout();
|
||||||
$('.cms-container').layout({resize: false})
|
this.find('.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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user