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:
Ingo Schommer 2011-12-20 14:10:39 +01:00
parent 068fcb209f
commit ac963755dd
2 changed files with 23 additions and 6 deletions

View File

@ -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('/'));
});
}

View File

@ -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});
},