Permalink
Browse files

MDL-33017 navigation: Tidied up after peer-review

  • Loading branch information...
Sam Hemelryk
Sam Hemelryk committed Nov 6, 2012
1 parent 05f6da1 commit b9c87ef86a6870e3d0f35414d0e9cdf827176455
Showing with 42 additions and 11 deletions.
  1. +39 −10 blocks/navigation/yui/navigation/navigation.js
  2. +3 −1 lib/ajax/getnavbranch.php
@@ -74,6 +74,35 @@ var EXPANSIONLIMIT_EVERYTHING = 0,
EXPANSIONLIMIT_SECTION = 30,
EXPANSIONLIMIT_ACTIVITY = 40;
/**
* Mappings for the different types of nodes coming from the navigation.
* Copied from lib/navigationlib.php navigation_node constants.
* @type object
*/
var NODETYPE = {
/** @type int Root node = 0 */
ROOTNODE : 0,
/** @type int System context = 1 */
SYSTEM : 1,
/** @type int Course category = 10 */
CATEGORY : 10,
/** @type int Course = 20 */
COURSE : 20,
/** @type int Course section = 30 */
SECTION : 30,
/** @type int Activity (course module) = 40 */
ACTIVITY : 40,
/** @type int Resource (course module = 50 */
RESOURCE : 50,
/** @type int Custom node (could be anything) = 60 */
CUSTOM : 60,
/** @type int Setting = 70 */
SETTING : 70,
/** @type int User context = 80 */
USER : 80,
/** @type int Container = 90 */
CONTAINER : 90
}
/**
* Navigation tree class.
@@ -299,7 +328,7 @@ BRANCH.prototype = {
// Prepare the icon, should be an object representing a pix_icon
var branchicon = false;
var icon = this.get('icon');
if (icon && (!isbranch || this.get('type') == 40)) {
if (icon && (!isbranch || this.get('type') == NODETYPE.ACTIVITY)) {
branchicon = Y.Node.create('<img alt="" />');
branchicon.setAttribute('src', M.util.image_url(icon.pix, icon.component));
branchli.addClass('item_with_icon');
@@ -419,13 +448,13 @@ BRANCH.prototype = {
var coursecount = 0;
for (var i in object.children) {
if (typeof(object.children[i])=='object') {
if (object.children[i].type == 20) {
if (object.children[i].type == NODETYPE.COURSE) {
coursecount++;
}
this.addChild(object.children[i]);
}
}
if ((this.get('type') == 10 || this.get('type') == 0) && coursecount >= M.block_navigation.courselimit) {
if ((this.get('type') == NODETYPE.CATEGORY || this.get('type') == NODETYPE.ROOTNODE) && coursecount >= M.block_navigation.courselimit) {
this.addViewAllCoursesChild(this);
}
this.get('tree').toggleExpansion({target:this.node});
@@ -450,14 +479,14 @@ BRANCH.prototype = {
var count = 0, i, children = branch.get('children');
for (i in children) {
// Add each branch to the tree
if (children[i].type == 20) {
if (children[i].type == NODETYPE.COURSE) {
count++;
}
if (typeof(children[i])=='object') {
branch.addChild(children[i]);
}
}
if (branch.get('type') == 10 && count >= M.block_navigation.courselimit) {
if (branch.get('type') == NODETYPE.CATEGORY && count >= M.block_navigation.courselimit) {
this.addViewAllCoursesChild(branch);
}
}
@@ -469,14 +498,14 @@ BRANCH.prototype = {
*/
addViewAllCoursesChild: function(branch) {
var url = null;
if (branch.get('type') == 0 ) {
if (branch.get('key') == 'mycourses') {
url = M.cfg.wwwroot+'/my';
if (branch.get('type') == NODETYPE.ROOTNODE) {
if (branch.get('key') === 'mycourses') {
url = M.cfg.wwwroot + '/my';
} else {
url = M.cfg.wwwroot+'/course/index.php';
url = M.cfg.wwwroot + '/course/index.php';
}
} else {
url = M.cfg.wwwroot+'/course/category.php?id='+branch.get('key');
url = M.cfg.wwwroot+'/course/category.php?id=' + branch.get('key');
}
branch.addChild({
name : M.str.moodle.viewallcourses,
@@ -35,7 +35,9 @@
try {
// Start buffer capture so that we can `remove` any errors
ob_start();
// Require id This is the key for whatever branch we want to get
// Require id This is the key for whatever branch we want to get.
// This accepts alphanum because the courses and my courses branches don't have numerical keys.
// For those branches we return the alphanum key, courses and mycourses.
$branchid = required_param('id', PARAM_ALPHANUM);
// This identifies the type of the branch we want to get
$branchtype = required_param('type', PARAM_INT);

0 comments on commit b9c87ef

Please sign in to comment.