mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Support for fake "redirects" in ajax responses via History.replaceState() (used e.g. for an add form loading the record for editing afterwards, under its own URL)
This commit is contained in:
parent
068fcb209f
commit
ac963755dd
@ -57,15 +57,20 @@
|
||||
|
||||
editPageItem[editPageItem.is('.current') ? 'show' : 'hide']();
|
||||
|
||||
// update the menu links to reflect the page ID if the page has changed the URL.
|
||||
// Update the menu links to reflect the page ID if the page has changed the URL.
|
||||
var currentID = $('.cms-content input[name=ID]').val();
|
||||
|
||||
// only handling the sub menu as the other items are global in context
|
||||
var itemsWithPageContext = [
|
||||
'#Menu-CMSPageAddController',
|
||||
'#Menu-CMSPageSettingsController',
|
||||
'#Menu-CMSPageHistoryController',
|
||||
'#Menu-CMSPageEditController'
|
||||
];
|
||||
if(currentID) {
|
||||
$(this).find("ul a").each(function(i, elem) {
|
||||
var links = $(this).find(itemsWithPageContext.join(',')).find('a');
|
||||
links.each(function(i, elem) {
|
||||
var href = $(elem).attr("href").split('/');
|
||||
href[href.length -1] = currentID;
|
||||
|
||||
// Assumes that current ID will always be the last URL segment (and not a query parameter)
|
||||
$(elem).attr('href', href.join('/'));
|
||||
});
|
||||
}
|
||||
|
@ -70,7 +70,13 @@
|
||||
self.redraw();
|
||||
});
|
||||
|
||||
$('.cms-edit-form').live('reloadeditform', function() {
|
||||
$('.cms-edit-form').live('reloadeditform', function(e, data) {
|
||||
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
|
||||
if(window.History.enabled) {
|
||||
var url = data.xmlhttp.getResponseHeader('X-ControllerURL');
|
||||
if(url) window.history.replaceState({}, '', url);
|
||||
}
|
||||
|
||||
self.redraw()
|
||||
});
|
||||
|
||||
@ -222,6 +228,12 @@
|
||||
self.redraw();
|
||||
newContentEl.css('visibility', 'visible');
|
||||
newContentEl.removeClass('loading');
|
||||
|
||||
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
|
||||
if(window.History.enabled) {
|
||||
var url = xhr.getResponseHeader('X-ControllerURL');
|
||||
if(url) window.history.replaceState({}, '', url);
|
||||
}
|
||||
|
||||
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: newContentEl});
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user