From 1af67ecb1a4cccb6f58bc10b98ab93a7f90c1ddf Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Thu, 1 Jul 2010 03:33:16 +0000 Subject: [PATCH] navigation MDL-23036 Fixed issue when generation was limited to course+categories causing JS to error --- blocks/navigation/block_navigation.php | 7 +++++++ blocks/navigation/navigation.js | 26 +++++++++++++++++--------- lib/navigationlib.php | 9 +++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/blocks/navigation/block_navigation.php b/blocks/navigation/block_navigation.php index db61ea7355d..6a3055a61e0 100644 --- a/blocks/navigation/block_navigation.php +++ b/blocks/navigation/block_navigation.php @@ -158,6 +158,13 @@ class block_navigation extends block_base { // Get the expandable items so we can pass them to JS $expandable = array(); $navigation->find_expandable($expandable); + if ($expansionlimit) { + foreach ($expandable as $key=>$node) { + if ($node['type'] > $expansionlimit && !($expansionlimit == navigation_node::TYPE_COURSE && $node['type'] == $expansionlimit && $node['branchid'] == SITEID)) { + unset($expandable[$key]); + } + } + } // Initialise the JS tree object $module = array('name'=>'block_navigation', 'fullpath'=>'/blocks/navigation/navigation.js', 'requires'=>array('core_dock', 'io', 'node', 'dom', 'event-custom', 'json-parse'), 'strings'=>array(array('viewallcourses','moodle'))); diff --git a/blocks/navigation/navigation.js b/blocks/navigation/navigation.js index df21f0cf18c..38672465672 100644 --- a/blocks/navigation/navigation.js +++ b/blocks/navigation/navigation.js @@ -106,10 +106,18 @@ M.block_navigation.classes.tree = function(Y, id, properties) { // Attach event to toggle expansion node.all('.tree_item.branch').on('click', this.toggleexpansion , this); - // Attache events to expand by AJAX + // Attach events to expand by AJAX + //var expandablenode; for (var i in this.expansions) { - this.Y.one('#'+this.expansions[i].id).on('ajaxload|click', this.init_load_ajax, this, this.expansions[i]); - M.block_navigation.expandablebranchcount++; + var expandablenode = Y.one('#'+this.expansions[i].id); + if (expandablenode) { + expandablenode.on('ajaxload|click', this.init_load_ajax, this, this.expansions[i]); + M.block_navigation.expandablebranchcount++; + } else if (M.cfg.debug) { + Y.one(document.body).append(Y.Node.create('
Expandable node within navigation was missing [#'+this.expansions[i].id+']
')); + } else { + // Failing over silently + } } if (node.hasClass('block_js_expansion')) { @@ -133,16 +141,16 @@ M.block_navigation.classes.tree.prototype.init_load_ajax = function(e, branch) { if (e.target.get('nodeName').toUpperCase() != 'P') { return true; } - var cfginstance = ''; + var cfginstance = '', Y = this.Y; if (this.instance != null) { cfginstance = '&instance='+this.instance } - this.Y.io(M.cfg.wwwroot+'/lib/ajax/getnavbranch.php', { + Y.io(M.cfg.wwwroot+'/lib/ajax/getnavbranch.php', { method:'POST', data:'elementid='+branch.id+'&id='+branch.branchid+'&type='+branch.type+'&sesskey='+M.cfg.sesskey+cfginstance, on: { complete:this.load_ajax, - success:function() {this.Y.detach('click', this.init_load_ajax, e.target);} + success:function() {Y.detach('click', this.init_load_ajax, e.target);} }, context:this, arguments:{ @@ -187,12 +195,12 @@ M.block_navigation.classes.tree.prototype.add_branch = function(branchobj, targe // Make the new branch into an object var branch = new M.block_navigation.classes.branch(this, branchobj); - var childrenul = false; + var childrenul = false, Y = this.Y; if (depth === 1) { if (!branch.children) { return false; } - childrenul = this.Y.Node.create(''); + childrenul = Y.Node.create(''); target.appendChild(childrenul); } else { childrenul = branch.inject_into_dom(target); @@ -302,7 +310,7 @@ M.block_navigation.classes.branch.prototype.inject_into_dom = function(element) var isbranch = ((this.expandable !== null || this.haschildren) && this.expansionceiling===null); var branchli = Y.Node.create('
  • '); - var branchp = this.tree.Y.Node.create('

    '); + var branchp = Y.Node.create('

    '); if (isbranch) { branchli.addClass('collapsed'); diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 8a968f63926..0e6e2ece616 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1875,7 +1875,16 @@ class global_navigation extends navigation_node { public function set_expansion_limit($type) { $nodes = $this->find_all_of_type($type); foreach ($nodes as &$node) { + // We need to generate the full site node + if ($type == self::TYPE_COURSE && $node->key == SITEID) { + continue; + } foreach ($node->children as &$child) { + // We still want to show course reports and participants containers + // or there will be navigation missing. + if ($type == self::TYPE_COURSE && $child->type === self::TYPE_CONTAINER) { + continue; + } $child->display = false; } }