mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-08 18:51:12 +02:00
Merge pull request #2657 from kinglozzer/cms-xhr-referer
NEW: Add X-Backurl header to CMS AJAX requests
This commit is contained in:
commit
651d3ea7fc
@ -284,9 +284,10 @@ jQuery.noConflict();
|
|||||||
* - {Object} data Any additional data passed through to History.pushState()
|
* - {Object} data Any additional data passed through to History.pushState()
|
||||||
* - {boolean} forceReload Forces the replacement of the current history state, even if the URL is the same, i.e. allows reloading.
|
* - {boolean} forceReload Forces the replacement of the current history state, even if the URL is the same, i.e. allows reloading.
|
||||||
*/
|
*/
|
||||||
loadPanel: function(url, title, data, forceReload) {
|
loadPanel: function(url, title, data, forceReload, forceReferer) {
|
||||||
if(!data) data = {};
|
if(!data) data = {};
|
||||||
if(!title) title = "";
|
if(!title) title = "";
|
||||||
|
if (!forceReferer) forceReferer = History.getState().url;
|
||||||
|
|
||||||
// Check change tracking (can't use events as we need a way to cancel the current state change)
|
// Check change tracking (can't use events as we need a way to cancel the current state change)
|
||||||
var contentEls = this._findFragments(data.pjax ? data.pjax.split(',') : ['Content']);
|
var contentEls = this._findFragments(data.pjax ? data.pjax.split(',') : ['Content']);
|
||||||
@ -306,6 +307,7 @@ jQuery.noConflict();
|
|||||||
this.saveTabState();
|
this.saveTabState();
|
||||||
|
|
||||||
if(window.History.enabled) {
|
if(window.History.enabled) {
|
||||||
|
$.extend(data, {__forceReferer: forceReferer});
|
||||||
// Active menu item is set based on X-Controller ajax header,
|
// Active menu item is set based on X-Controller ajax header,
|
||||||
// which matches one class on the menu
|
// which matches one class on the menu
|
||||||
if(forceReload) {
|
if(forceReload) {
|
||||||
@ -458,6 +460,12 @@ jQuery.noConflict();
|
|||||||
// is fired, so the server might decide to change it based on its own logic.
|
// is fired, so the server might decide to change it based on its own logic.
|
||||||
headers['X-Pjax'] = fragments;
|
headers['X-Pjax'] = fragments;
|
||||||
|
|
||||||
|
// Set 'fake' referer - we call pushState() before making the AJAX request, so we have to
|
||||||
|
// set our own referer here
|
||||||
|
if (typeof state.data.__forceReferer !== 'undefined') {
|
||||||
|
headers['X-Backurl'] = state.data.__forceReferer;
|
||||||
|
}
|
||||||
|
|
||||||
contentEls.addClass('loading');
|
contentEls.addClass('loading');
|
||||||
var xhr = $.ajax({
|
var xhr = $.ajax({
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
@ -498,6 +498,8 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
|
|||||||
if($this->request) {
|
if($this->request) {
|
||||||
if($this->request->requestVar('BackURL')) {
|
if($this->request->requestVar('BackURL')) {
|
||||||
$url = $this->request->requestVar('BackURL');
|
$url = $this->request->requestVar('BackURL');
|
||||||
|
} else if($this->request->isAjax() && $this->request->getHeader('X-Backurl')) {
|
||||||
|
$url = $this->request->getHeader('X-Backurl');
|
||||||
} else if($this->request->getHeader('Referer')) {
|
} else if($this->request->getHeader('Referer')) {
|
||||||
$url = $this->request->getHeader('Referer');
|
$url = $this->request->getHeader('Referer');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user