insert a 'View all courses' link when loading category navigation entries from AJAX

This commit is contained in:
Jonathon Fowler 2011-03-18 15:00:14 +10:00
parent 56babbcb76
commit c683165a4a
2 changed files with 24 additions and 8 deletions

View file

@ -310,11 +310,18 @@ BRANCH.prototype = {
try { try {
var object = Y.JSON.parse(outcome.responseText); var object = Y.JSON.parse(outcome.responseText);
if (object.children && object.children.length > 0) { if (object.children && object.children.length > 0) {
var count = 0;
for (var i in object.children) { for (var i in object.children) {
if (object.children[i].type == 20) {
count++;
}
if (typeof(object.children[i])=='object') { if (typeof(object.children[i])=='object') {
this.addChild(object.children[i]); this.addChild(object.children[i]);
} }
} }
if (this.get('type') == 10 && count >= M.block_navigation.courselimit) {
this.addViewAllCoursesChild(this);
}
this.get('tree').toggleExpansion({target:this.node}); this.get('tree').toggleExpansion({target:this.node});
return true; return true;
} }
@ -345,16 +352,23 @@ BRANCH.prototype = {
} }
} }
if (branch.get('type') == 10 && count >= M.block_navigation.courselimit) { if (branch.get('type') == 10 && count >= M.block_navigation.courselimit) {
branch.addChild({ this.addViewAllCoursesChild(branch);
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);
} }
} }
return true; 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, { Y.extend(BRANCH, Y.Base, BRANCH.prototype, {

View file

@ -1098,6 +1098,8 @@ class global_navigation extends navigation_node {
$this->rootnodes['courses']->add(get_string('viewallcoursescategories'), new moodle_url('/course/index.php'), self::TYPE_SETTING); $this->rootnodes['courses']->add(get_string('viewallcoursescategories'), new moodle_url('/course/index.php'), self::TYPE_SETTING);
} }
$this->page->requires->string_for_js('viewallcourses', 'moodle');
// Load for the current user // Load for the current user
$this->load_for_user(); $this->load_for_user();
if ($this->page->context->contextlevel >= CONTEXT_COURSE && $this->page->context->instanceid != SITEID && $canviewcourseprofile) { if ($this->page->context->contextlevel >= CONTEXT_COURSE && $this->page->context->instanceid != SITEID && $canviewcourseprofile) {