mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-43272 JavaScript: Migrate moodle-course-modchooser to use Shifter
This commit is contained in:
parent
c36a2401ab
commit
43736b7dd0
7 changed files with 548 additions and 166 deletions
178
course/yui/build/moodle-course-modchooser/moodle-course-modchooser-debug.js
vendored
Normal file
178
course/yui/build/moodle-course-modchooser/moodle-course-modchooser-debug.js
vendored
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
YUI.add('moodle-course-modchooser', function (Y, NAME) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The activity chooser dialogue for courses.
|
||||||
|
*
|
||||||
|
* @moodle-course-modchooser
|
||||||
|
*/
|
||||||
|
|
||||||
|
var CSS = {
|
||||||
|
PAGECONTENT : 'div#page-content',
|
||||||
|
SECTION : 'li.section',
|
||||||
|
SECTIONMODCHOOSER : 'span.section-modchooser-link',
|
||||||
|
SITEMENU : 'div.block_site_main_menu',
|
||||||
|
SITETOPIC : 'div.sitetopic'
|
||||||
|
};
|
||||||
|
|
||||||
|
var MODCHOOSERNAME = 'course-modchooser';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The activity chooser dialogue for courses.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @class M.course.modchooser
|
||||||
|
* @extends M.core.chooserdialogue
|
||||||
|
*/
|
||||||
|
var MODCHOOSER = function() {
|
||||||
|
MODCHOOSER.superclass.constructor.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||||
|
// The current section ID
|
||||||
|
sectionid : null,
|
||||||
|
|
||||||
|
// The hidden element holding the jump param
|
||||||
|
jumplink : null,
|
||||||
|
|
||||||
|
initializer : function() {
|
||||||
|
var dialogue = Y.one('.chooserdialoguebody');
|
||||||
|
var header = Y.one('.choosertitle');
|
||||||
|
var params = {};
|
||||||
|
this.setup_chooser_dialogue(dialogue, header, params);
|
||||||
|
|
||||||
|
// Initialize existing sections and register for dynamically created sections
|
||||||
|
this.setup_for_section();
|
||||||
|
M.course.coursebase.register_module(this);
|
||||||
|
|
||||||
|
// Catch the page toggle
|
||||||
|
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Update any section areas within the scope of the specified
|
||||||
|
* selector with AJAX equivalents
|
||||||
|
*
|
||||||
|
* @param baseselector The selector to limit scope to
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
setup_for_section : function(baseselector) {
|
||||||
|
if (!baseselector) {
|
||||||
|
baseselector = CSS.PAGECONTENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup for site topics
|
||||||
|
Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Setup for standard course topics
|
||||||
|
Y.one(baseselector).all(CSS.SECTION).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Setup for the block site menu
|
||||||
|
Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
_setup_for_section : function(section) {
|
||||||
|
var chooserspan = section.one(CSS.SECTIONMODCHOOSER);
|
||||||
|
if (!chooserspan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var chooserlink = Y.Node.create("<a href='#' />");
|
||||||
|
chooserspan.get('children').each(function(node) {
|
||||||
|
chooserlink.appendChild(node);
|
||||||
|
});
|
||||||
|
chooserspan.insertBefore(chooserlink);
|
||||||
|
chooserlink.on('click', this.display_mod_chooser, this);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Display the module chooser
|
||||||
|
*
|
||||||
|
* @param e Event Triggering Event
|
||||||
|
* @param secitonid integer The ID of the section triggering the dialogue
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
display_mod_chooser : function (e) {
|
||||||
|
// Set the section for this version of the dialogue
|
||||||
|
if (e.target.ancestor(CSS.SITETOPIC)) {
|
||||||
|
// The site topic has a sectionid of 1
|
||||||
|
this.sectionid = 1;
|
||||||
|
} else if (e.target.ancestor(CSS.SECTION)) {
|
||||||
|
var section = e.target.ancestor(CSS.SECTION);
|
||||||
|
this.sectionid = section.get('id').replace('section-', '');
|
||||||
|
} else if (e.target.ancestor(CSS.SITEMENU)) {
|
||||||
|
// The block site menu has a sectionid of 0
|
||||||
|
this.sectionid = 0;
|
||||||
|
}
|
||||||
|
this.display_chooser(e);
|
||||||
|
},
|
||||||
|
toggle_mod_chooser : function(e) {
|
||||||
|
// Get the add section link
|
||||||
|
var modchooserlinks = Y.all('div.addresourcemodchooser');
|
||||||
|
|
||||||
|
// Get the dropdowns
|
||||||
|
var dropdowns = Y.all('div.addresourcedropdown');
|
||||||
|
|
||||||
|
if (modchooserlinks.size() === 0) {
|
||||||
|
// Continue with non-js action if there are no modchoosers to add
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to update the text and link
|
||||||
|
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
|
||||||
|
|
||||||
|
// The actual text is in the last child
|
||||||
|
var toggletext = togglelink.get('lastChild');
|
||||||
|
|
||||||
|
var usemodchooser;
|
||||||
|
// Determine whether they're currently hidden
|
||||||
|
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
|
||||||
|
// The modchooser is currently visible, hide it
|
||||||
|
usemodchooser = 0;
|
||||||
|
modchooserlinks
|
||||||
|
.removeClass('visibleifjs')
|
||||||
|
.addClass('hiddenifjs');
|
||||||
|
dropdowns
|
||||||
|
.addClass('visibleifjs')
|
||||||
|
.removeClass('hiddenifjs');
|
||||||
|
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
|
||||||
|
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
|
||||||
|
} else {
|
||||||
|
// The modchooser is currently not visible, show it
|
||||||
|
usemodchooser = 1;
|
||||||
|
modchooserlinks
|
||||||
|
.addClass('visibleifjs')
|
||||||
|
.removeClass('hiddenifjs');
|
||||||
|
dropdowns
|
||||||
|
.removeClass('visibleifjs')
|
||||||
|
.addClass('hiddenifjs');
|
||||||
|
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
|
||||||
|
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
|
||||||
|
}
|
||||||
|
|
||||||
|
M.util.set_user_preference('usemodchooser', usemodchooser);
|
||||||
|
|
||||||
|
// Prevent the page from reloading
|
||||||
|
e.preventDefault();
|
||||||
|
},
|
||||||
|
option_selected : function(thisoption) {
|
||||||
|
// Add the sectionid to the URL
|
||||||
|
this.jumplink.set('value', thisoption.get('value') + '§ion=' + this.sectionid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME : MODCHOOSERNAME,
|
||||||
|
ATTRS : {
|
||||||
|
maxheight : {
|
||||||
|
value : 800
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
M.course = M.course || {};
|
||||||
|
M.course.init_chooser = function(config) {
|
||||||
|
return new MODCHOOSER(config);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}, '@VERSION@', {"requires": ["moodle-core-chooserdialogue", "moodle-course-coursebase"]});
|
1
course/yui/build/moodle-course-modchooser/moodle-course-modchooser-min.js
vendored
Normal file
1
course/yui/build/moodle-course-modchooser/moodle-course-modchooser-min.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
YUI.add("moodle-course-modchooser",function(e,t){var n={PAGECONTENT:"div#page-content",SECTION:"li.section",SECTIONMODCHOOSER:"span.section-modchooser-link",SITEMENU:"div.block_site_main_menu",SITETOPIC:"div.sitetopic"},r="course-modchooser",i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,M.core.chooserdialogue,{sectionid:null,jumplink:null,initializer:function(){var t=e.one(".chooserdialoguebody"),n=e.one(".choosertitle"),r={};this.setup_chooser_dialogue(t,n,r),this.setup_for_section(),M.course.coursebase.register_module(this),e.all(".block_settings #settingsnav .type_course .modchoosertoggle a").on("click",this.toggle_mod_chooser,this)},setup_for_section:function(t){t||(t=n.PAGECONTENT),e.one(t).all(n.SITETOPIC).each(function(e){this._setup_for_section(e)},this),e.one(t).all(n.SECTION).each(function(e){this._setup_for_section(e)},this),e.one(t).all(n.SITEMENU).each(function(e){this._setup_for_section(e)},this)},_setup_for_section:function(t){var r=t.one(n.SECTIONMODCHOOSER);if(!r)return;var i=e.Node.create("<a href='#' />");r.get("children").each(function(e){i.appendChild(e)}),r.insertBefore(i),i.on("click",this.display_mod_chooser,this)},display_mod_chooser:function(e){if(e.target.ancestor(n.SITETOPIC))this.sectionid=1;else if(e.target.ancestor(n.SECTION)){var t=e.target.ancestor(n.SECTION);this.sectionid=t.get("id").replace("section-","")}else e.target.ancestor(n.SITEMENU)&&(this.sectionid=0);this.display_chooser(e)},toggle_mod_chooser:function(t){var n=e.all("div.addresourcemodchooser"),r=e.all("div.addresourcedropdown");if(n.size()===0)return;var i=e.one(".block_settings #settingsnav .type_course .modchoosertoggle a"),s=i.get("lastChild"),o;n.item(0).hasClass("visibleifjs")?(o=0,n.removeClass("visibleifjs").addClass("hiddenifjs"),r.addClass("visibleifjs").removeClass("hiddenifjs"),s.set("data",M.util.get_string("modchooserenable","moodle")),i.set("href",i.get("href").replace("off","on"))):(o=1,n.addClass("visibleifjs").removeClass("hiddenifjs"),r.removeClass("visibleifjs").addClass("hiddenifjs"),s.set("data",M.util.get_string("modchooserdisable","moodle")),i.set("href",i.get("href").replace("on","off"))),M.util.set_user_preference("usemodchooser",o),t.preventDefault()},option_selected:function(e){this.jumplink.set("value",e.get("value")+"§ion="+this.sectionid)}},{NAME:r,ATTRS:{maxheight:{value:800}}}),M.course=M.course||{},M.course.init_chooser=function(e){return new i(e)}},"@VERSION@",{requires:["moodle-core-chooserdialogue","moodle-course-coursebase"]});
|
178
course/yui/build/moodle-course-modchooser/moodle-course-modchooser.js
vendored
Normal file
178
course/yui/build/moodle-course-modchooser/moodle-course-modchooser.js
vendored
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
YUI.add('moodle-course-modchooser', function (Y, NAME) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The activity chooser dialogue for courses.
|
||||||
|
*
|
||||||
|
* @moodle-course-modchooser
|
||||||
|
*/
|
||||||
|
|
||||||
|
var CSS = {
|
||||||
|
PAGECONTENT : 'div#page-content',
|
||||||
|
SECTION : 'li.section',
|
||||||
|
SECTIONMODCHOOSER : 'span.section-modchooser-link',
|
||||||
|
SITEMENU : 'div.block_site_main_menu',
|
||||||
|
SITETOPIC : 'div.sitetopic'
|
||||||
|
};
|
||||||
|
|
||||||
|
var MODCHOOSERNAME = 'course-modchooser';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The activity chooser dialogue for courses.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @class M.course.modchooser
|
||||||
|
* @extends M.core.chooserdialogue
|
||||||
|
*/
|
||||||
|
var MODCHOOSER = function() {
|
||||||
|
MODCHOOSER.superclass.constructor.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||||
|
// The current section ID
|
||||||
|
sectionid : null,
|
||||||
|
|
||||||
|
// The hidden element holding the jump param
|
||||||
|
jumplink : null,
|
||||||
|
|
||||||
|
initializer : function() {
|
||||||
|
var dialogue = Y.one('.chooserdialoguebody');
|
||||||
|
var header = Y.one('.choosertitle');
|
||||||
|
var params = {};
|
||||||
|
this.setup_chooser_dialogue(dialogue, header, params);
|
||||||
|
|
||||||
|
// Initialize existing sections and register for dynamically created sections
|
||||||
|
this.setup_for_section();
|
||||||
|
M.course.coursebase.register_module(this);
|
||||||
|
|
||||||
|
// Catch the page toggle
|
||||||
|
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Update any section areas within the scope of the specified
|
||||||
|
* selector with AJAX equivalents
|
||||||
|
*
|
||||||
|
* @param baseselector The selector to limit scope to
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
setup_for_section : function(baseselector) {
|
||||||
|
if (!baseselector) {
|
||||||
|
baseselector = CSS.PAGECONTENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup for site topics
|
||||||
|
Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Setup for standard course topics
|
||||||
|
Y.one(baseselector).all(CSS.SECTION).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Setup for the block site menu
|
||||||
|
Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
_setup_for_section : function(section) {
|
||||||
|
var chooserspan = section.one(CSS.SECTIONMODCHOOSER);
|
||||||
|
if (!chooserspan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var chooserlink = Y.Node.create("<a href='#' />");
|
||||||
|
chooserspan.get('children').each(function(node) {
|
||||||
|
chooserlink.appendChild(node);
|
||||||
|
});
|
||||||
|
chooserspan.insertBefore(chooserlink);
|
||||||
|
chooserlink.on('click', this.display_mod_chooser, this);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Display the module chooser
|
||||||
|
*
|
||||||
|
* @param e Event Triggering Event
|
||||||
|
* @param secitonid integer The ID of the section triggering the dialogue
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
display_mod_chooser : function (e) {
|
||||||
|
// Set the section for this version of the dialogue
|
||||||
|
if (e.target.ancestor(CSS.SITETOPIC)) {
|
||||||
|
// The site topic has a sectionid of 1
|
||||||
|
this.sectionid = 1;
|
||||||
|
} else if (e.target.ancestor(CSS.SECTION)) {
|
||||||
|
var section = e.target.ancestor(CSS.SECTION);
|
||||||
|
this.sectionid = section.get('id').replace('section-', '');
|
||||||
|
} else if (e.target.ancestor(CSS.SITEMENU)) {
|
||||||
|
// The block site menu has a sectionid of 0
|
||||||
|
this.sectionid = 0;
|
||||||
|
}
|
||||||
|
this.display_chooser(e);
|
||||||
|
},
|
||||||
|
toggle_mod_chooser : function(e) {
|
||||||
|
// Get the add section link
|
||||||
|
var modchooserlinks = Y.all('div.addresourcemodchooser');
|
||||||
|
|
||||||
|
// Get the dropdowns
|
||||||
|
var dropdowns = Y.all('div.addresourcedropdown');
|
||||||
|
|
||||||
|
if (modchooserlinks.size() === 0) {
|
||||||
|
// Continue with non-js action if there are no modchoosers to add
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to update the text and link
|
||||||
|
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
|
||||||
|
|
||||||
|
// The actual text is in the last child
|
||||||
|
var toggletext = togglelink.get('lastChild');
|
||||||
|
|
||||||
|
var usemodchooser;
|
||||||
|
// Determine whether they're currently hidden
|
||||||
|
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
|
||||||
|
// The modchooser is currently visible, hide it
|
||||||
|
usemodchooser = 0;
|
||||||
|
modchooserlinks
|
||||||
|
.removeClass('visibleifjs')
|
||||||
|
.addClass('hiddenifjs');
|
||||||
|
dropdowns
|
||||||
|
.addClass('visibleifjs')
|
||||||
|
.removeClass('hiddenifjs');
|
||||||
|
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
|
||||||
|
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
|
||||||
|
} else {
|
||||||
|
// The modchooser is currently not visible, show it
|
||||||
|
usemodchooser = 1;
|
||||||
|
modchooserlinks
|
||||||
|
.addClass('visibleifjs')
|
||||||
|
.removeClass('hiddenifjs');
|
||||||
|
dropdowns
|
||||||
|
.removeClass('visibleifjs')
|
||||||
|
.addClass('hiddenifjs');
|
||||||
|
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
|
||||||
|
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
|
||||||
|
}
|
||||||
|
|
||||||
|
M.util.set_user_preference('usemodchooser', usemodchooser);
|
||||||
|
|
||||||
|
// Prevent the page from reloading
|
||||||
|
e.preventDefault();
|
||||||
|
},
|
||||||
|
option_selected : function(thisoption) {
|
||||||
|
// Add the sectionid to the URL
|
||||||
|
this.jumplink.set('value', thisoption.get('value') + '§ion=' + this.sectionid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME : MODCHOOSERNAME,
|
||||||
|
ATTRS : {
|
||||||
|
maxheight : {
|
||||||
|
value : 800
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
M.course = M.course || {};
|
||||||
|
M.course.init_chooser = function(config) {
|
||||||
|
return new MODCHOOSER(config);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}, '@VERSION@', {"requires": ["moodle-core-chooserdialogue", "moodle-course-coursebase"]});
|
166
course/yui/modchooser/modchooser.js
vendored
166
course/yui/modchooser/modchooser.js
vendored
|
@ -1,166 +0,0 @@
|
||||||
YUI.add('moodle-course-modchooser', function(Y) {
|
|
||||||
var CSS = {
|
|
||||||
PAGECONTENT : 'div#page-content',
|
|
||||||
SECTION : 'li.section',
|
|
||||||
SECTIONMODCHOOSER : 'span.section-modchooser-link',
|
|
||||||
SITEMENU : 'div.block_site_main_menu',
|
|
||||||
SITETOPIC : 'div.sitetopic'
|
|
||||||
};
|
|
||||||
|
|
||||||
var MODCHOOSERNAME = 'course-modchooser';
|
|
||||||
|
|
||||||
var MODCHOOSER = function() {
|
|
||||||
MODCHOOSER.superclass.constructor.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
|
||||||
// The current section ID
|
|
||||||
sectionid : null,
|
|
||||||
|
|
||||||
// The hidden element holding the jump param
|
|
||||||
jumplink : null,
|
|
||||||
|
|
||||||
initializer : function(config) {
|
|
||||||
var dialogue = Y.one('.chooserdialoguebody');
|
|
||||||
var header = Y.one('.choosertitle');
|
|
||||||
var params = {};
|
|
||||||
this.setup_chooser_dialogue(dialogue, header, params);
|
|
||||||
|
|
||||||
// Initialize existing sections and register for dynamically created sections
|
|
||||||
this.setup_for_section();
|
|
||||||
M.course.coursebase.register_module(this);
|
|
||||||
|
|
||||||
// Catch the page toggle
|
|
||||||
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Update any section areas within the scope of the specified
|
|
||||||
* selector with AJAX equivalents
|
|
||||||
*
|
|
||||||
* @param baseselector The selector to limit scope to
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
setup_for_section : function(baseselector) {
|
|
||||||
if (!baseselector) {
|
|
||||||
var baseselector = CSS.PAGECONTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup for site topics
|
|
||||||
Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
|
|
||||||
this._setup_for_section(section);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
// Setup for standard course topics
|
|
||||||
Y.one(baseselector).all(CSS.SECTION).each(function(section) {
|
|
||||||
this._setup_for_section(section);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
// Setup for the block site menu
|
|
||||||
Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
|
|
||||||
this._setup_for_section(section);
|
|
||||||
}, this);
|
|
||||||
},
|
|
||||||
_setup_for_section : function(section, sectionid) {
|
|
||||||
var chooserspan = section.one(CSS.SECTIONMODCHOOSER);
|
|
||||||
if (!chooserspan) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var chooserlink = Y.Node.create("<a href='#' />");
|
|
||||||
chooserspan.get('children').each(function(node) {
|
|
||||||
chooserlink.appendChild(node);
|
|
||||||
});
|
|
||||||
chooserspan.insertBefore(chooserlink);
|
|
||||||
chooserlink.on('click', this.display_mod_chooser, this);
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Display the module chooser
|
|
||||||
*
|
|
||||||
* @param e Event Triggering Event
|
|
||||||
* @param secitonid integer The ID of the section triggering the dialogue
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
display_mod_chooser : function (e) {
|
|
||||||
// Set the section for this version of the dialogue
|
|
||||||
if (e.target.ancestor(CSS.SITETOPIC)) {
|
|
||||||
// The site topic has a sectionid of 1
|
|
||||||
this.sectionid = 1;
|
|
||||||
} else if (e.target.ancestor(CSS.SECTION)) {
|
|
||||||
var section = e.target.ancestor(CSS.SECTION);
|
|
||||||
this.sectionid = section.get('id').replace('section-', '');
|
|
||||||
} else if (e.target.ancestor(CSS.SITEMENU)) {
|
|
||||||
// The block site menu has a sectionid of 0
|
|
||||||
this.sectionid = 0;
|
|
||||||
}
|
|
||||||
this.display_chooser(e);
|
|
||||||
},
|
|
||||||
toggle_mod_chooser : function(e) {
|
|
||||||
// Get the add section link
|
|
||||||
var modchooserlinks = Y.all('div.addresourcemodchooser');
|
|
||||||
|
|
||||||
// Get the dropdowns
|
|
||||||
var dropdowns = Y.all('div.addresourcedropdown');
|
|
||||||
|
|
||||||
if (modchooserlinks.size() == 0) {
|
|
||||||
// Continue with non-js action if there are no modchoosers to add
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to update the text and link
|
|
||||||
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
|
|
||||||
|
|
||||||
// The actual text is in the last child
|
|
||||||
var toggletext = togglelink.get('lastChild');
|
|
||||||
|
|
||||||
var usemodchooser;
|
|
||||||
// Determine whether they're currently hidden
|
|
||||||
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
|
|
||||||
// The modchooser is currently visible, hide it
|
|
||||||
usemodchooser = 0;
|
|
||||||
modchooserlinks
|
|
||||||
.removeClass('visibleifjs')
|
|
||||||
.addClass('hiddenifjs');
|
|
||||||
dropdowns
|
|
||||||
.addClass('visibleifjs')
|
|
||||||
.removeClass('hiddenifjs');
|
|
||||||
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
|
|
||||||
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
|
|
||||||
} else {
|
|
||||||
// The modchooser is currently not visible, show it
|
|
||||||
usemodchooser = 1;
|
|
||||||
modchooserlinks
|
|
||||||
.addClass('visibleifjs')
|
|
||||||
.removeClass('hiddenifjs');
|
|
||||||
dropdowns
|
|
||||||
.removeClass('visibleifjs')
|
|
||||||
.addClass('hiddenifjs');
|
|
||||||
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
|
|
||||||
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
|
|
||||||
}
|
|
||||||
|
|
||||||
M.util.set_user_preference('usemodchooser', usemodchooser);
|
|
||||||
|
|
||||||
// Prevent the page from reloading
|
|
||||||
e.preventDefault();
|
|
||||||
},
|
|
||||||
option_selected : function(thisoption) {
|
|
||||||
// Add the sectionid to the URL
|
|
||||||
this.jumplink.set('value', thisoption.get('value') + '§ion=' + this.sectionid);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
NAME : MODCHOOSERNAME,
|
|
||||||
ATTRS : {
|
|
||||||
maxheight : {
|
|
||||||
value : 800
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
M.course = M.course || {};
|
|
||||||
M.course.init_chooser = function(config) {
|
|
||||||
return new MODCHOOSER(config);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'@VERSION@', {
|
|
||||||
requires:['base', 'overlay', 'moodle-core-chooserdialogue', 'moodle-course-coursebase']
|
|
||||||
}
|
|
||||||
);
|
|
10
course/yui/src/modchooser/build.json
Normal file
10
course/yui/src/modchooser/build.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "moodle-course-modchooser",
|
||||||
|
"builds": {
|
||||||
|
"moodle-course-modchooser": {
|
||||||
|
"jsfiles": [
|
||||||
|
"modchooser.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
173
course/yui/src/modchooser/js/modchooser.js
vendored
Normal file
173
course/yui/src/modchooser/js/modchooser.js
vendored
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
/**
|
||||||
|
* The activity chooser dialogue for courses.
|
||||||
|
*
|
||||||
|
* @moodle-course-modchooser
|
||||||
|
*/
|
||||||
|
|
||||||
|
var CSS = {
|
||||||
|
PAGECONTENT : 'div#page-content',
|
||||||
|
SECTION : 'li.section',
|
||||||
|
SECTIONMODCHOOSER : 'span.section-modchooser-link',
|
||||||
|
SITEMENU : 'div.block_site_main_menu',
|
||||||
|
SITETOPIC : 'div.sitetopic'
|
||||||
|
};
|
||||||
|
|
||||||
|
var MODCHOOSERNAME = 'course-modchooser';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The activity chooser dialogue for courses.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @class M.course.modchooser
|
||||||
|
* @extends M.core.chooserdialogue
|
||||||
|
*/
|
||||||
|
var MODCHOOSER = function() {
|
||||||
|
MODCHOOSER.superclass.constructor.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||||
|
// The current section ID
|
||||||
|
sectionid : null,
|
||||||
|
|
||||||
|
// The hidden element holding the jump param
|
||||||
|
jumplink : null,
|
||||||
|
|
||||||
|
initializer : function() {
|
||||||
|
var dialogue = Y.one('.chooserdialoguebody');
|
||||||
|
var header = Y.one('.choosertitle');
|
||||||
|
var params = {};
|
||||||
|
this.setup_chooser_dialogue(dialogue, header, params);
|
||||||
|
|
||||||
|
// Initialize existing sections and register for dynamically created sections
|
||||||
|
this.setup_for_section();
|
||||||
|
M.course.coursebase.register_module(this);
|
||||||
|
|
||||||
|
// Catch the page toggle
|
||||||
|
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Update any section areas within the scope of the specified
|
||||||
|
* selector with AJAX equivalents
|
||||||
|
*
|
||||||
|
* @param baseselector The selector to limit scope to
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
setup_for_section : function(baseselector) {
|
||||||
|
if (!baseselector) {
|
||||||
|
baseselector = CSS.PAGECONTENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup for site topics
|
||||||
|
Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Setup for standard course topics
|
||||||
|
Y.one(baseselector).all(CSS.SECTION).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Setup for the block site menu
|
||||||
|
Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
|
||||||
|
this._setup_for_section(section);
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
_setup_for_section : function(section) {
|
||||||
|
var chooserspan = section.one(CSS.SECTIONMODCHOOSER);
|
||||||
|
if (!chooserspan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var chooserlink = Y.Node.create("<a href='#' />");
|
||||||
|
chooserspan.get('children').each(function(node) {
|
||||||
|
chooserlink.appendChild(node);
|
||||||
|
});
|
||||||
|
chooserspan.insertBefore(chooserlink);
|
||||||
|
chooserlink.on('click', this.display_mod_chooser, this);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Display the module chooser
|
||||||
|
*
|
||||||
|
* @param e Event Triggering Event
|
||||||
|
* @param secitonid integer The ID of the section triggering the dialogue
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
display_mod_chooser : function (e) {
|
||||||
|
// Set the section for this version of the dialogue
|
||||||
|
if (e.target.ancestor(CSS.SITETOPIC)) {
|
||||||
|
// The site topic has a sectionid of 1
|
||||||
|
this.sectionid = 1;
|
||||||
|
} else if (e.target.ancestor(CSS.SECTION)) {
|
||||||
|
var section = e.target.ancestor(CSS.SECTION);
|
||||||
|
this.sectionid = section.get('id').replace('section-', '');
|
||||||
|
} else if (e.target.ancestor(CSS.SITEMENU)) {
|
||||||
|
// The block site menu has a sectionid of 0
|
||||||
|
this.sectionid = 0;
|
||||||
|
}
|
||||||
|
this.display_chooser(e);
|
||||||
|
},
|
||||||
|
toggle_mod_chooser : function(e) {
|
||||||
|
// Get the add section link
|
||||||
|
var modchooserlinks = Y.all('div.addresourcemodchooser');
|
||||||
|
|
||||||
|
// Get the dropdowns
|
||||||
|
var dropdowns = Y.all('div.addresourcedropdown');
|
||||||
|
|
||||||
|
if (modchooserlinks.size() === 0) {
|
||||||
|
// Continue with non-js action if there are no modchoosers to add
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to update the text and link
|
||||||
|
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
|
||||||
|
|
||||||
|
// The actual text is in the last child
|
||||||
|
var toggletext = togglelink.get('lastChild');
|
||||||
|
|
||||||
|
var usemodchooser;
|
||||||
|
// Determine whether they're currently hidden
|
||||||
|
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
|
||||||
|
// The modchooser is currently visible, hide it
|
||||||
|
usemodchooser = 0;
|
||||||
|
modchooserlinks
|
||||||
|
.removeClass('visibleifjs')
|
||||||
|
.addClass('hiddenifjs');
|
||||||
|
dropdowns
|
||||||
|
.addClass('visibleifjs')
|
||||||
|
.removeClass('hiddenifjs');
|
||||||
|
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
|
||||||
|
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
|
||||||
|
} else {
|
||||||
|
// The modchooser is currently not visible, show it
|
||||||
|
usemodchooser = 1;
|
||||||
|
modchooserlinks
|
||||||
|
.addClass('visibleifjs')
|
||||||
|
.removeClass('hiddenifjs');
|
||||||
|
dropdowns
|
||||||
|
.removeClass('visibleifjs')
|
||||||
|
.addClass('hiddenifjs');
|
||||||
|
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
|
||||||
|
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
|
||||||
|
}
|
||||||
|
|
||||||
|
M.util.set_user_preference('usemodchooser', usemodchooser);
|
||||||
|
|
||||||
|
// Prevent the page from reloading
|
||||||
|
e.preventDefault();
|
||||||
|
},
|
||||||
|
option_selected : function(thisoption) {
|
||||||
|
// Add the sectionid to the URL
|
||||||
|
this.jumplink.set('value', thisoption.get('value') + '§ion=' + this.sectionid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NAME : MODCHOOSERNAME,
|
||||||
|
ATTRS : {
|
||||||
|
maxheight : {
|
||||||
|
value : 800
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
M.course = M.course || {};
|
||||||
|
M.course.init_chooser = function(config) {
|
||||||
|
return new MODCHOOSER(config);
|
||||||
|
};
|
8
course/yui/src/modchooser/meta/modchooser.json
Normal file
8
course/yui/src/modchooser/meta/modchooser.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"moodle-course-modchooser": {
|
||||||
|
"requires": [
|
||||||
|
"moodle-core-chooserdialogue",
|
||||||
|
"moodle-course-coursebase"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue