BUGFIX: Preserve selection of LHS multiselect tree when switching between filters. (from r90290)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@96806 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-01-13 00:05:48 +00:00
parent a53967b266
commit ae10403240
2 changed files with 30 additions and 10 deletions

View File

@ -148,6 +148,7 @@ SiteTreeFilter.prototype = {
onSuccess: function() { onSuccess: function() {
indicator.style.display = 'none'; indicator.style.display = 'none';
if(__makeDraggableAfterUpdate) $('sitetree').makeDraggable(); if(__makeDraggableAfterUpdate) $('sitetree').makeDraggable();
batchActionGlobals.refreshSelected();
}, },
onFailure: function(response) { onFailure: function(response) {
errorMessage('Could not update tree', response); errorMessage('Could not update tree', response);
@ -301,7 +302,9 @@ batchactionsclass.prototype = {
batchActionGlobals = { batchActionGlobals = {
selectedNodes: { }, selectedNodes: { },
// count Int - The number of nodes selected // count Int - The number of nodes selected
count: { }, count: function() {
return batchActionGlobals.getIds().length;
},
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875 // TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
newNodes: { }, newNodes: { },
treeSelectionChanged : function(selectedNode) { treeSelectionChanged : function(selectedNode) {
@ -337,6 +340,7 @@ batchActionGlobals = {
popupClosed : function() { popupClosed : function() {
removeClass($('sitetree'),'multiselect'); removeClass($('sitetree'),'multiselect');
$('sitetree').stopObserving(batchActionGlobals.o1); $('sitetree').stopObserving(batchActionGlobals.o1);
$(_HANDLER_FORMS.batchactions).stopObserving(batchActionGlobals.o2); $(_HANDLER_FORMS.batchactions).stopObserving(batchActionGlobals.o2);
@ -352,7 +356,7 @@ batchActionGlobals = {
batchActionGlobals.selectedNodes = { }; batchActionGlobals.selectedNodes = { };
}, },
getCsvIds : function() { getIds: function() {
var csvIDs = new Array(); var csvIDs = new Array();
var st = $('sitetree'); var st = $('sitetree');
batchActionGlobals.newNodes = new Array(); batchActionGlobals.newNodes = new Array();
@ -375,8 +379,17 @@ batchActionGlobals = {
} }
} }
} }
batchActionGlobals.count=csvIDs.length; return csvIDs;
return (csvIDs.toString()); },
getCsvIds : function() {
return (batchActionGlobals.getIds().toString());
},
refreshSelected : function() {
var st = $('sitetree');
for(var idx in batchActionGlobals.selectedNodes) {
st.getTreeNodeByIdx(idx).addNodeClass('selected');
st.getTreeNodeByIdx(idx).selected = true;
}
}, },
unfilterSiteTree : function() { unfilterSiteTree : function() {
// Reload the site tree if it has been filtered // Reload the site tree if it has been filtered
@ -427,7 +440,7 @@ publishpage.prototype = {
var ingText = optionParams.doingText; var ingText = optionParams.doingText;
// Confirmation // Confirmation
if(!confirm("You have " + batchActionGlobals.count + " pages selected.\n\nDo your really want to " + actionText.toLowerCase() + "?")) { if(!confirm("You have " + batchActionGlobals.count() + " pages selected.\n\nDo your really want to " + actionText.toLowerCase() + "?")) {
return false; return false;
} }
@ -470,11 +483,10 @@ deletepage.prototype = {
onsubmit : function() { onsubmit : function() {
csvIDs = batchActionGlobals.getCsvIds(); csvIDs = batchActionGlobals.getCsvIds();
if(csvIDs || batchActionGlobals.newNodes.length > 0) { if(csvIDs || batchActionGlobals.newNodes.length > 0) {
batchActionGlobals.count += batchActionGlobals.newNodes.length;
if(confirm(ss.i18n.sprintf( if(confirm(ss.i18n.sprintf(
ss.i18n._t('CMSMAIN.REALLYDELETEPAGES'), ss.i18n._t('CMSMAIN.REALLYDELETEPAGES'),
batchActionGlobals.count batchActionGlobals.count()
))) { ))) {
this.elements.csvIDs.value = csvIDs; this.elements.csvIDs.value = csvIDs;

View File

@ -231,10 +231,18 @@ TreeNodeAPI.prototype = {
url = this.tree.url(args); url = this.tree.url(args);
new Ajax.Request(url, { new Ajax.Request(url, {
onSuccess : this.installSubtree.bind(this), onSuccess : this.installSubtreeAndRefresh.bind(this),
onFailure : this.showSubtreeLoadingError onFailure : this.showSubtreeLoadingError
}); });
}, },
installSubtreeAndRefresh : function(response){
this.installSubtree(response);
if(this.tree.className.indexOf('multiselect') != -1) {
batchActionGlobals.refreshSelected();
}
},
showSubtreeLoadingError: function(response) { showSubtreeLoadingError: function(response) {
errorMessage('error loading subtree', response); errorMessage('error loading subtree', response);
}, },