ENHANCEMENT Query ajaxExpansion on tree nodes without node limitation on serverside (see Hierarchy->markPartialTree()) to avoid "missing" nodes during the selection

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@81458 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-07-09 05:36:47 +00:00
parent 119121b0f2
commit fece6769fe
2 changed files with 29 additions and 7 deletions

View File

@ -496,7 +496,7 @@ class LeftAndMain extends Controller {
* @param $childrenMethod The method to call to get the children of the tree. For example,
* Children, AllChildrenIncludingDeleted, or AllHistoricalChildren
*/
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $filterFunction = null) {
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
// Default childrenMethod
if (!$childrenMethod) $childrenMethod = 'AllChildrenIncludingDeleted';
@ -505,19 +505,27 @@ class LeftAndMain extends Controller {
// Mark the nodes of the tree to return
if ($filterFunction) $obj->setMarkingFilterFunction($filterFunction);
$obj->markPartialTree(30, $this, $childrenMethod);
$obj->markPartialTree($minNodeCount, $this, $childrenMethod);
// Ensure current page is exposed
if($p = $this->currentPage()) $obj->markToExpose($p);
// getChildrenAsUL is a flexible and complex way of traversing the tree
$siteTree = $obj->getChildrenAsUL("", '
$titleEval = '
"<li id=\"record-$child->ID\" class=\"" . $child->CMSTreeClasses($extraArg) . "\">" .
"<a href=\"" . Director::link(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" class=\"" . $child->CMSTreeClasses($extraArg) . "\" title=\"' . _t('LeftAndMain.PAGETYPE','Page type: ') . '".$child->class."\" >" .
($child->TreeTitle()) .
"</a>"
'
,$this, true, $childrenMethod);
';
$siteTree = $obj->getChildrenAsUL(
"",
$titleEval,
$this,
true,
$childrenMethod,
$minNodeCount
);
// Wrap the root if needs be.
@ -539,9 +547,16 @@ class LeftAndMain extends Controller {
* Get a subtree underneath the request param 'ID'.
* If ID = 0, then get the whole tree.
*/
public function getsubtree() {
public function getsubtree($request) {
// Get the tree
$tree = $this->getSiteTreeFor($this->stat('tree_class'), $_REQUEST['ID']);
$minNodeCount = (is_numeric($request->getVar('minNodeCount'))) ? $request->getVar('minNodeCount') : NULL;
$tree = $this->getSiteTreeFor(
$this->stat('tree_class'),
$request->getVar('ID'),
null,
null,
$minNodeCount
);
// Trim off the outer tag
$tree = ereg_replace('^[ \t\r\n]*<ul[^>]*>','', $tree);

View File

@ -219,8 +219,15 @@ TreeNodeAPI.prototype = {
}
var args = {ajax:1, ID:this.getIdx()};
// Add current locale for any subtree selection
if ($('LangSelector')) args.locale = $('LangSelector').value;
// If the tree is selectable, we have to show all available children without
// artificial limitations from the serverside (minNodeCount). This is a measure
// to ensure no unexpanded nodes are missed in batch selection
if(Element.hasClassName('sitetree', 'multiselect')) args.minNodeCount = 0;
url = this.tree.url(args);
new Ajax.Request(url, {