Merge branch 'MDL-26875' of git://github.com/samhemelryk/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 21 Mar 2011 20:10:55 +0000 (21:10 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 21 Mar 2011 20:10:55 +0000 (21:10 +0100)
blocks/navigation/block_navigation.php
blocks/navigation/yui/navigation/navigation.js

index 71ad007..77cc00a 100644 (file)
@@ -118,6 +118,7 @@ class block_navigation extends block_base {
             'courselimit'    => $limit,
             'expansionlimit' => $expansionlimit
         );
+        $this->page->requires->string_for_js('viewallcourses', 'moodle');
         $this->page->requires->yui_module(array('core_dock', 'moodle-block_navigation-navigation'), 'M.block_navigation.init_add_tree', array($arguments));
     }
 
index f2522d8..1dfb76a 100644 (file)
@@ -310,11 +310,18 @@ BRANCH.prototype = {
         try {
             var object = Y.JSON.parse(outcome.responseText);
             if (object.children && object.children.length > 0) {
+                var coursecount = 0;
                 for (var i in object.children) {
                     if (typeof(object.children[i])=='object') {
+                        if (object.children[i].type == 20) {
+                            coursecount++;
+                        }
                         this.addChild(object.children[i]);
                     }
                 }
+                if (this.get('type') == 10 && coursecount >= M.block_navigation.courselimit) {
+                    this.addViewAllCoursesChild(this);
+                }
                 this.get('tree').toggleExpansion({target:this.node});
                 return true;
             }
@@ -345,16 +352,23 @@ BRANCH.prototype = {
                 }
             }
             if (branch.get('type') == 10 && count >= M.block_navigation.courselimit) {
-                branch.addChild({
-                    name : M.str.moodle.viewallcourses,
-                    title : M.str.moodle.viewallcourses,
-                    link : M.cfg.wwwroot+'/course/category.php?id='+branch.get('key'),
-                    haschildren : false,
-                    icon : {'pix':"i/navigationitem",'component':'moodle'}
-                }, branch);
+                this.addViewAllCoursesChild(branch);
             }
         }
         return true;
+    },
+
+    /**
+     * Add a link to view all courses in a category
+     */
+    addViewAllCoursesChild: function(branch) {
+        branch.addChild({
+            name : M.str.moodle.viewallcourses,
+            title : M.str.moodle.viewallcourses,
+            link : M.cfg.wwwroot+'/course/category.php?id='+branch.get('key'),
+            haschildren : false,
+            icon : {'pix':"i/navigationitem",'component':'moodle'}
+        });
     }
 }
 Y.extend(BRANCH, Y.Base, BRANCH.prototype, {