navigation MDL-23036 Fixed issue when generation was limited to course+categories...
authorSam Hemelryk <sam@moodle.com>
Thu, 1 Jul 2010 03:33:16 +0000 (03:33 +0000)
committerSam Hemelryk <sam@moodle.com>
Thu, 1 Jul 2010 03:33:16 +0000 (03:33 +0000)
blocks/navigation/block_navigation.php
blocks/navigation/navigation.js
lib/navigationlib.php

index db61ea7..6a3055a 100644 (file)
@@ -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')));
index df21f0c..3867246 100644 (file)
@@ -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('<div class="notification" style="font-size:6pt;">Expandable node within navigation was missing [#'+this.expansions[i].id+']</div>'));
+        } 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('<ul></ul>');
+        childrenul = Y.Node.create('<ul></ul>');
         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('<li></li>');
-    var branchp = this.tree.Y.Node.create('<p class="tree_item"></p>');
+    var branchp = Y.Node.create('<p class="tree_item"></p>');
 
     if (isbranch) {
         branchli.addClass('collapsed');
index 8a968f6..0e6e2ec 100644 (file)
@@ -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;
             }
         }