1 YUI.add('moodle-course-modchooser', function (Y, NAME) {
4 * The activity chooser dialogue for courses.
6 * @module moodle-course-modchooser
12 SECTIONMODCHOOSER: 'button.section-modchooser-link',
13 SITEMENU: '.block_site_main_menu',
14 SITETOPIC: 'div.sitetopic'
17 var MODCHOOSERNAME = 'course-modchooser';
20 * The activity chooser dialogue for courses.
23 * @class M.course.modchooser
24 * @extends M.core.chooserdialogue
26 var MODCHOOSER = function() {
27 MODCHOOSER.superclass.constructor.apply(this, arguments);
30 Y.extend(MODCHOOSER, M.core.chooserdialogue, {
32 * The current section ID.
42 * Set up the activity chooser.
46 initializer: function() {
47 var sectionclass = M.course.format.get_sectionwrapperclass();
49 CSS.SECTION = '.' + sectionclass;
51 var dialogue = Y.one('.chooserdialoguebody');
52 var header = Y.one('.choosertitle');
54 this.setup_chooser_dialogue(dialogue, header, params);
56 // Initialize existing sections and register for dynamically created sections
57 this.setup_for_section();
58 M.course.coursebase.register_module(this);
62 * Update any section areas within the scope of the specified
63 * selector with AJAX equivalents
65 * @method setup_for_section
66 * @param baseselector The selector to limit scope to
68 setup_for_section: function(baseselector) {
70 baseselector = CSS.PAGECONTENT;
73 // Setup for site topics
74 Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
75 this._setup_for_section(section);
78 // Setup for standard course topics
80 Y.one(baseselector).all(CSS.SECTION).each(function(section) {
81 this._setup_for_section(section);
85 // Setup for the block site menu
86 Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
87 this._setup_for_section(section);
92 * Update any section areas within the scope of the specified
93 * selector with AJAX equivalents
95 * @method _setup_for_section
97 * @param baseselector The selector to limit scope to
99 _setup_for_section: function(section) {
100 var chooserspan = section.one(CSS.SECTIONMODCHOOSER);
104 var chooserlink = Y.Node.create("<a href='#' />");
105 chooserspan.get('children').each(function(node) {
106 chooserlink.appendChild(node);
108 chooserspan.insertBefore(chooserlink);
109 chooserlink.on('click', this.display_mod_chooser, this);
112 * Display the module chooser
114 * @method display_mod_chooser
115 * @param {EventFacade} e Triggering Event
117 display_mod_chooser: function(e) {
118 // Set the section for this version of the dialogue
119 if (e.target.ancestor(CSS.SITETOPIC)) {
120 // The site topic has a sectionid of 1
122 } else if (e.target.ancestor(CSS.SECTION)) {
123 var section = e.target.ancestor(CSS.SECTION);
124 this.sectionid = section.get('id').replace('section-', '');
125 } else if (e.target.ancestor(CSS.SITEMENU)) {
126 // The block site menu has a sectionid of 0
129 this.display_chooser(e);
133 * Helper function to set the value of a hidden radio button when a
136 * @method option_selected
137 * @param {String} thisoption The selected option value
140 option_selected: function(thisoption) {
141 // Add the sectionid to the URL.
142 this.hiddenRadioValue.setAttrs({
144 value: thisoption.get('value') + '§ion=' + this.sectionid
149 NAME: MODCHOOSERNAME,
152 * The maximum height (in pixels) of the activity chooser.
154 * @attribute maxheight
163 M.course = M.course || {};
164 M.course.init_chooser = function(config) {
165 return new MODCHOOSER(config);
169 }, '@VERSION@', {"requires": ["moodle-core-chooserdialogue", "moodle-course-coursebase"]});