MINOR Moved tree filtering in LeftAndMain from SiteTreeAsUL() into getSiteTreeFor() to allow filtering the initial tree (via GET parameters), rather than just through getsubtree()

This commit is contained in:
Ingo Schommer 2012-04-16 22:05:50 +02:00
parent 9b2b39aaaa
commit 0ef5d0b84f
2 changed files with 18 additions and 16 deletions

View File

@ -590,10 +590,22 @@ class LeftAndMain extends Controller implements PermissionProvider {
* @return String Nested unordered list with links to each page
*/
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
// Filter criteria
$params = $this->request->getVar('q');
if(isset($params['FilterClass']) && $filterClass = $params['FilterClass']){
if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
}
$filter = new $filterClass($params);
} else {
$filter = null;
}
// Default childrenMethod and numChildrenMethod
if (!$childrenMethod) $childrenMethod = 'AllChildrenIncludingDeleted';
if (!$numChildrenMethod) $numChildrenMethod = 'numChildren';
if(!$childrenMethod) $childrenMethod = ($filter && $filter->getChildrenMethod()) ? $filter->getChildrenMethod() : 'AllChildrenIncludingDeleted';
if(!$numChildrenMethod) $numChildrenMethod = 'numChildren';
if(!$filterFunction) $filterFunction = ($filter) ? array($filter, 'isPageIncluded') : null;
// Get the tree root
$record = ($rootID) ? $this->getRecord($rootID) : null;
$obj = $record ? $record : singleton($className);
@ -657,22 +669,12 @@ class LeftAndMain extends Controller implements PermissionProvider {
* If ID = 0, then get the whole tree.
*/
public function getsubtree($request) {
if($filterClass = $request->requestVar('FilterClass')) {
if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
}
$filter = new $filterClass($request->requestVars());
} else {
$filter = null;
}
$html = $this->getSiteTreeFor(
$this->stat('tree_class'),
$request->getVar('ID'),
($filter) ? $filter->getChildrenMethod() : null,
null,
null,
($filter) ? array($filter, 'isPageIncluded') : null,
null,
$request->getVar('minNodeCount')
);

View File

@ -213,7 +213,7 @@
};
var handledform = $(e.target).is('.cms-edit-form') ? $(e.target)[0] : $(e.target).find('.cms-edit-form')[0];
var id = $(handledform.ID).val();
var id = handledform ? $(handledform.ID).val() : null;
// check if a form with a valid ID exists
if(id) {