Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

blocks-navigation MDL-25596 Fixed up redundant AJAX calls when naviga…

…tion was limited by config
  • Loading branch information...
commit 8e5c23e04ff278fa6addec308add60db65ff5ba1 1 parent 46f4c39
@samhemelryk samhemelryk authored
View
8 blocks/navigation/block_navigation.php
@@ -107,7 +107,13 @@ function get_required_javascript() {
if (!empty($CFG->navcourselimit)) {
$limit = $CFG->navcourselimit;
}
- $arguments = array('id'=>$this->instance->id, 'instance'=>$this->instance->id, 'candock'=>$this->instance_can_be_docked(), 'courselimit'=>$limit);
+ $arguments = array(
+ 'id' => $this->instance->id,
+ 'instance' => $this->instance->id,
+ 'candock' => $this->instance_can_be_docked(),
+ 'courselimit' => $limit,
+ 'expansionlimit' => $this->config->expansionlimit
+ );
$this->page->requires->yui_module(array('core_dock', 'moodle-block_navigation-navigation'), 'M.block_navigation.init_add_tree', array($arguments));
}
View
14 blocks/navigation/renderer.php
@@ -21,13 +21,16 @@ protected function navigation_node($items, $attrs=array(), $expansionlimit=null,
// array of nested li elements
$lis = array();
foreach ($items as $item) {
- if (!$item->display) {
+ if (!$item->display && !$item->contains_active_node()) {
continue;
}
$content = $item->get_content();
$title = $item->get_title();
- $isbranch = ($item->type !== $expansionlimit && ($item->children->count() > 0 || ($item->nodetype == navigation_node::NODETYPE_BRANCH && $item->children->count()==0 && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY))));
- $hasicon = ((!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY)&& $item->icon instanceof renderable);
+
+ $isexpandable = (empty($expansionlimit) || ($item->type > navigation_node::TYPE_ACTIVITY || $item->type < $expansionlimit) || ($item->contains_active_node() && $item->children->count() > 0));
+ $isbranch = $isexpandable && ($item->children->count() > 0 || ($item->has_children() && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY)));
+
+ $hasicon = ((!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY )&& $item->icon instanceof renderable);
if ($hasicon) {
$icon = $this->output->render($item->icon);
@@ -91,7 +94,10 @@ protected function navigation_node($items, $attrs=array(), $expansionlimit=null,
if (!empty($item->id)) {
$divattr['id'] = $item->id;
}
- $content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item->children, array(), $expansionlimit, $options, $depth+1);
+ $content = html_writer::tag('p', $content, $divattr);
+ if ($isexpandable) {
+ $content .= $this->navigation_node($item->children, array(), $expansionlimit, $options, $depth+1);
+ }
if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
$content = html_writer::empty_tag('hr') . $content;
}
View
20 blocks/navigation/yui/navigation/navigation.js
@@ -1,5 +1,11 @@
YUI.add('moodle-block_navigation-navigation', function(Y){
+var EXPANSIONLIMIT_EVERYTHING = 0,
+ EXPANSIONLIMIT_COURSE = 20,
+ EXPANSIONLIMIT_SECTION = 30,
+ EXPANSIONLIMIT_ACTIVITY = 40;
+
+
/**
* Navigation tree class.
*
@@ -119,6 +125,12 @@ Y.extend(TREE, Y.Base, TREE.prototype, {
accordian : {
validator : Y.Lang.isBool,
value : false
+ },
+ expansionlimit : {
+ value : 0,
+ setter : function(val) {
+ return parseInt(val);
+ }
}
}
});
@@ -161,7 +173,15 @@ BRANCH.prototype = {
this.set(i, config.overrides[i]);
}
}
+ // Get the node for this branch
this.node = Y.one('#', this.get('id'));
+ // Now check whether the branch is not expandable because of the expansionlimit
+ var expansionlimit = this.get('tree').get('expansionlimit');
+ var type = this.get('type');
+ if (expansionlimit != EXPANSIONLIMIT_EVERYTHING && type >= expansionlimit && type <= EXPANSIONLIMIT_ACTIVITY) {
+ this.set('expandable', false);
+ this.set('haschildren', false);
+ }
},
/**
* Draws the branch within the tree.
Please sign in to comment.
Something went wrong with that request. Please try again.