MINOR Update CMS menu state on form submission (as well as history state change)

This commit is contained in:
Ingo Schommer 2011-12-20 17:06:40 +01:00
parent 225776389a
commit 30377f277e

View File

@ -29,13 +29,20 @@
$('.cms-menu-list').entwine({ $('.cms-menu-list').entwine({
onmatch: function() { onmatch: function() {
var self = this; var self = this;
$('.cms-container').bind('afterstatechange', function(e, data) {
var controller = data.xhr.getResponseHeader('X-Controller'); var updateMenuFromResponse = function(xhr) {
var controller = xhr.getResponseHeader('X-Controller');
if(controller) { if(controller) {
var item = self.find('li#Menu-' + controller); var item = self.find('li#Menu-' + controller);
if(!item.hasClass('current')) item.select(); if(!item.hasClass('current')) item.select();
} }
self.updateItems(); self.updateItems();
};
$('.cms-container').live('afterstatechange', function(e, data) {
updateMenuFromResponse(data.xhr);
});
$('.cms-edit-form').live('reloadeditform', function(e, data) {
updateMenuFromResponse(data.xmlhttp);
}); });
// Sync collapsed state with parent panel // Sync collapsed state with parent panel
@ -59,19 +66,9 @@
// 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(); var currentID = $('.cms-content input[name=ID]').val();
var itemsWithPageContext = [
'#Menu-CMSPageAddController',
'#Menu-CMSPageSettingsController',
'#Menu-CMSPageHistoryController',
'#Menu-CMSPageEditController'
];
if(currentID) { if(currentID) {
var links = $(this).find(itemsWithPageContext.join(',')).find('a'); this.find('li').each(function() {
links.each(function(i, elem) { if($.isFunction($(this).setRecordID)) $(this).setRecordID(currentID);
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('/'));
}); });
} }
} }
@ -151,6 +148,23 @@
} }
}); });
$('.cms-menu-list #Menu-CMSPageSettingsController, .cms-menu-list #Menu-CMSPageHistoryController, .cms-menu-list #Menu-CMSPageEditController').entwine({
setRecordID: function(id) {
var link = this.find('a:first'), href = link.attr("href").split('/')
// Assumes that current ID will always be the last URL segment (and not a query parameter)
href[href.length -1] = id;
link.attr('href', href.join('/'));
}
})
$('.cms-menu-list #Menu-CMSPageAddController').entwine({
setRecordID: function(id) {
var link = this.find('a:first');
link.attr('href', link.attr('href').replace('/\?.*/', '?ParentID=' . id));
}
});
}); });
// Internal Helper // Internal Helper