MDL-35590 block_navigation: fix remaining issues

This commit is contained in:
Simey Lameze 2016-01-22 17:54:38 +08:00
parent 10ac8baf6e
commit 6759dc35fe
15 changed files with 101 additions and 75 deletions

View file

@ -0,0 +1 @@
define(["jquery"],function(a){function b(d,e){var f=a("<ul></ul>");f.attr("role","group"),a.each(e,function(d,e){if("object"==typeof e){var g=a("<li></li>"),h=a("<p></p>"),i=null,j=e.expandable||e.haschildren?!0:!1;if(h.addClass("tree_item"),h.attr("id",e.id),g.attr("role","treeitem"),e.requiresajaxloading&&(g.attr("data-requires-ajax",!0),g.attr("data-node-id",e.id),g.attr("data-node-key",e.key),g.attr("data-node-type",e.type)),j&&(g.addClass("collapsed contains_branch"),g.attr("aria-expanded",!1),h.addClass("branch")),!e.icon||j&&e.type!==c.ACTIVITY&&e.type!==c.RESOURCE||(g.addClass("item_with_icon"),h.addClass("hasicon"),i=a("<img/>"),i.attr("alt",e.icon.alt),i.attr("title",e.icon.title),i.attr("src",M.util.image_url(e.icon.pix,e.icon.component)),a.each(e.icon.classes,function(a,b){i.addClass(b)})),e.link){var k=a("<a></a>");k.attr("title",e.title),k.attr("href",e.link),i?(k.append(i),k.append('<span class="item-content-wrap">'+e.name+"</span>")):k.text(e.name),e.hidden&&k.addClass("dimmed"),h.append(k)}else{var l=a("<span></span>");i?(l.append(i),l.append('<span class="item-content-wrap">'+e.name+"</span>")):l.text(e.name),e.hidden&&l.addClass("dimmed"),h.append(l)}g.append(h),f.append(g),e.children&&e.children.length?b(g,e.children):j&&!e.requiresajaxloading&&(g.removeClass("contains_branch"),g.addClass("emptybranch"))}}),d.append(f)}var c={ROOTNODE:0,SYSTEM:1,CATEGORY:10,MYCATEGORY:11,COURSE:20,SECTION:30,ACTIVITY:40,RESOURCE:50,CUSTOM:60,SETTING:70,SITEADMIN:71,USER:80,CONTAINER:90};return{render:function(a,c){c.children&&c.children.length?b(a,c.children):a.hasClass("contains_branch")&&a.removeClass("contains_branch").addClass("emptybranch")}}});

View file

@ -0,0 +1 @@
define(["jquery","core/ajax","core/config","block_navigation/ajax_response_renderer"],function(a,b,c,d){function e(a){return a.closest("[data-block]").attr("data-instanceid")}var f=c.wwwroot+"/lib/ajax/getnavbranch.php";return{load:function(b){b=a(b);var g=a.Deferred(),h={elementid:b.attr("data-node-id"),id:b.attr("data-node-key"),type:b.attr("data-node-type"),sesskey:c.sesskey,instance:e(b)},i={type:"POST",dataType:"json",data:h};return a.ajax(f,i).done(function(a){d.render(b,a),g.resolve()}),g}}});

View file

@ -0,0 +1 @@
define(["jquery","core/tree"],function(a,b){return{init:function(){new b(".block_navigation .block_tree")}}});

View file

@ -0,0 +1 @@
define(["jquery","core/ajax","core/config","block_navigation/ajax_response_renderer"],function(a,b,c,d){var e=71,f=c.wwwroot+"/lib/ajax/getsiteadminbranch.php";return{load:function(b){b=a(b);var g=a.Deferred(),h={type:e,sesskey:c.sesskey},i={type:"POST",dataType:"json",data:h};return a.ajax(f,i).done(function(a){d.render(b,a),g.resolve()}),g}}});

View file

@ -27,34 +27,42 @@ define(['jquery'], function($) {
// Mappings for the different types of nodes coming from the navigation.
// Copied from lib/navigationlib.php navigation_node constants.
var NODETYPE = {
// @type int Root node = 0
// @type int Root node = 0.
ROOTNODE : 0,
// @type int System context = 1
// @type int System context = 1.
SYSTEM : 1,
// @type int Course category = 10
// @type int Course category = 10.
CATEGORY : 10,
// @type int MYCATEGORY = 11
// @type int MYCATEGORY = 11.
MYCATEGORY : 11,
// @type int Course = 20
// @type int Course = 20.
COURSE : 20,
// @type int Course section = 30
// @type int Course section = 30.
SECTION : 30,
// @type int Activity (course module) = 40
// @type int Activity (course module) = 40.
ACTIVITY : 40,
// @type int Resource (course module = 50
// @type int Resource (course module = 50.
RESOURCE : 50,
// @type int Custom node (could be anything) = 60
// @type int Custom node (could be anything) = 60.
CUSTOM : 60,
// @type int Setting = 70
// @type int Setting = 70.
SETTING : 70,
// @type int site administration = 71
// @type int site administration = 71.
SITEADMIN : 71,
// @type int User context = 80
// @type int User context = 80.
USER : 80,
// @type int Container = 90
// @type int Container = 90.
CONTAINER : 90
};
/**
* Build DOM.
*
* @method buildDOM
* @param {Object} rootElement the root element of DOM.
* @param {object} nodes jquery object representing the nodes to be build.
* @return
*/
function buildDOM(rootElement, nodes) {
var ul = $('<ul></ul>');
ul.attr('role', 'group');
@ -149,8 +157,7 @@ define(['jquery'], function($) {
return {
render: function(element, nodes) {
// The first element of the response is the existing node
// so we start with processing the children.
// The first element of the response is the existing node so we start with processing the children.
if (nodes.children && nodes.children.length) {
buildDOM(element, nodes.children);
} else {

View file

@ -22,13 +22,19 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_renderer'],
function($, ajax, config, renderer) {
function($, ajax, config, renderer) {
var URL = config.wwwroot + '/lib/ajax/getnavbranch.php';
var URL = config.wwwroot + '/lib/ajax/getnavbranch.php';
function getBlockInstanceId(element) {
return element.closest('[data-block]').attr('data-instanceid');
}
/**
* Get the block instance id.
*
* @function getBlockInstanceId
* @param element
* @returns {*}
*/
function getBlockInstanceId(element) {
return element.closest('[data-block]').attr('data-instanceid');
}
return {
load: function(element) {

View file

@ -14,7 +14,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Load the navtree javscript
* Load the navigation tree javascript.
*
* @module block_navigation/navblock
* @package core

View file

@ -33,7 +33,7 @@ define(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_re
var promise = $.Deferred();
var data = {
type: SITE_ADMIN_NODE_TYPE,
sesskey: config.sesskey,
sesskey: config.sesskey
};
var settings = {
type: 'POST',

View file

@ -107,7 +107,6 @@ class block_navigation extends block_base {
* Gets Javascript that may be required for navigation
*/
function get_required_javascript() {
global $CFG;
parent::get_required_javascript();
$this->page->requires->string_for_js('viewallcourses', 'moodle');
$this->page->requires->js_call_amd('block_navigation/navblock', 'init', array());
@ -119,6 +118,7 @@ class block_navigation extends block_base {
* @return object $this->content
*/
function get_content() {
global $CFG;
// First check if we have already generated, don't waste cycles
if ($this->contentgenerated === true) {
return $this->content;

View file

@ -182,7 +182,8 @@ class block_navigation_renderer extends plugin_renderer_base {
// Create the structure.
$content = html_writer::tag('p', $content, $divattr);
if ($isexpandable) {
$content .= $this->navigation_node($item->children, array('role' => 'group'), $expansionlimit, $options, $depth+1);
$content .= $this->navigation_node($item->children, array('role' => 'group'), $expansionlimit,
$options, $depth + 1);
}
if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
$content = html_writer::empty_tag('hr') . $content;