2 * The activity chooser dialogue for courses.
4 * @module moodle-course-modchooser
10 SECTIONMODCHOOSER: 'span.section-modchooser-link',
11 SITEMENU: '.block_site_main_menu',
12 SITETOPIC: 'div.sitetopic'
15 var MODCHOOSERNAME = 'course-modchooser';
18 * The activity chooser dialogue for courses.
21 * @class M.course.modchooser
22 * @extends M.core.chooserdialogue
24 var MODCHOOSER = function() {
25 MODCHOOSER.superclass.constructor.apply(this, arguments);
28 Y.extend(MODCHOOSER, M.core.chooserdialogue, {
30 * The current section ID.
40 * Set up the activity chooser.
44 initializer: function() {
45 var sectionclass = M.course.format.get_sectionwrapperclass();
47 CSS.SECTION = '.' + sectionclass;
49 var dialogue = Y.one('.chooserdialoguebody');
50 var header = Y.one('.choosertitle');
52 this.setup_chooser_dialogue(dialogue, header, params);
54 // Initialize existing sections and register for dynamically created sections
55 this.setup_for_section();
56 M.course.coursebase.register_module(this);
60 * Update any section areas within the scope of the specified
61 * selector with AJAX equivalents
63 * @method setup_for_section
64 * @param baseselector The selector to limit scope to
66 setup_for_section: function(baseselector) {
68 baseselector = CSS.PAGECONTENT;
71 // Setup for site topics
72 Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
73 this._setup_for_section(section);
76 // Setup for standard course topics
78 Y.one(baseselector).all(CSS.SECTION).each(function(section) {
79 this._setup_for_section(section);
83 // Setup for the block site menu
84 Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
85 this._setup_for_section(section);
90 * Update any section areas within the scope of the specified
91 * selector with AJAX equivalents
93 * @method _setup_for_section
95 * @param baseselector The selector to limit scope to
97 _setup_for_section: function(section) {
98 var chooserspan = section.one(CSS.SECTIONMODCHOOSER);
102 var chooserlink = Y.Node.create("<a href='#' />");
103 chooserspan.get('children').each(function(node) {
104 chooserlink.appendChild(node);
106 chooserspan.insertBefore(chooserlink);
107 chooserlink.on('click', this.display_mod_chooser, this);
110 * Display the module chooser
112 * @method display_mod_chooser
113 * @param {EventFacade} e Triggering Event
115 display_mod_chooser: function(e) {
116 // Set the section for this version of the dialogue
117 if (e.target.ancestor(CSS.SITETOPIC)) {
118 // The site topic has a sectionid of 1
120 } else if (e.target.ancestor(CSS.SECTION)) {
121 var section = e.target.ancestor(CSS.SECTION);
122 this.sectionid = section.get('id').replace('section-', '');
123 } else if (e.target.ancestor(CSS.SITEMENU)) {
124 // The block site menu has a sectionid of 0
127 this.display_chooser(e);
131 * Helper function to set the value of a hidden radio button when a
134 * @method option_selected
135 * @param {String} thisoption The selected option value
138 option_selected: function(thisoption) {
139 // Add the sectionid to the URL.
140 this.hiddenRadioValue.setAttrs({
142 value: thisoption.get('value') + '§ion=' + this.sectionid
147 NAME: MODCHOOSERNAME,
150 * The maximum height (in pixels) of the activity chooser.
152 * @attribute maxheight
161 M.course = M.course || {};
162 M.course.init_chooser = function(config) {
163 return new MODCHOOSER(config);