[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-tool_monitor-dropdown', function (Y, NAME) { 2 3 /** 4 * A module to manage dropdowns on the rule add/edit form. 5 * 6 * @module moodle-tool_monitor-dropdown 7 */ 8 9 /** 10 * A module to manage dependent selects on the edit page. 11 * 12 * @since Moodle 2.8 13 * @class moodle-tool_monitor.dropdown 14 * @extends Base 15 * @constructor 16 */ 17 function DropDown() { 18 DropDown.superclass.constructor.apply(this, arguments); 19 } 20 21 22 var SELECTORS = { 23 PLUGIN: '#id_plugin', 24 EVENTNAME: '#id_eventname', 25 OPTION: 'option', 26 CHOOSE: 'option[value=""]' 27 }; 28 29 Y.extend(DropDown, Y.Base, { 30 31 /** 32 * Reference to the plugin node. 33 * 34 * @property plugin 35 * @type Object 36 * @default null 37 * @protected 38 */ 39 plugin: null, 40 41 /** 42 * Reference to the plugin node. 43 * 44 * @property eventname 45 * @type Object 46 * @default null 47 * @protected 48 */ 49 eventname: null, 50 51 /** 52 * Initializer. 53 * Basic setup and delegations. 54 * 55 * @method initializer 56 */ 57 initializer: function() { 58 this.plugin = Y.one(SELECTORS.PLUGIN); 59 this.eventname = Y.one(SELECTORS.EVENTNAME); 60 var selection = this.eventname.get('value'); // Get selected event name. 61 this.updateEventsList(); 62 this.updateSelection(selection); 63 this.plugin.on('change', this.updateEventsList, this); 64 }, 65 66 /** 67 * Method to update the events list drop down when plugin list drop down is changed. 68 * 69 * @method updateEventsList 70 */ 71 updateEventsList: function() { 72 var node, options, choosenode; 73 var plugin = this.plugin.get('value'); // Get component name. 74 var namespace = '\\' + plugin + '\\'; 75 this.eventname.all(SELECTORS.OPTION).remove(true); // Delete all nodes. 76 options = this.get('eventlist'); 77 78 // Mark the default choose node as visible and selected. 79 choosenode = Y.Node.create('<option value="">' + options[''] + '</option>'); 80 choosenode.set('selected', 'selected'); 81 this.eventname.appendChild(choosenode); 82 83 Y.Object.each(options, function(value, key) { 84 // Make sure we highlight only nodes with correct namespace. 85 if (key.substring(0, namespace.length) === namespace) { 86 node = Y.Node.create('<option value="' + key + '">' + value + '</option>'); 87 this.eventname.appendChild(node); 88 } 89 }, this); 90 91 }, 92 93 /** 94 * Method to update the selected node from the options list. 95 * 96 * @method updateSelection 97 * @param {string} selection The options node value that should be selected. 98 */ 99 updateSelection: function(selection) { 100 this.eventname.get('options').each(function(opt) { 101 if (opt.get('value') === selection) { 102 opt.set('selected', 'selected'); 103 } 104 }, this); 105 } 106 }, { 107 NAME: 'dropDown', 108 ATTRS: { 109 /** 110 * A list of events with components. 111 * 112 * @attribute eventlist 113 * @default null 114 * @type Object 115 */ 116 eventlist: null 117 } 118 }); 119 120 Y.namespace('M.tool_monitor.DropDown').init = function(config) { 121 return new DropDown(config); 122 }; 123 124 125 }, '@VERSION@', {"requires": ["base", "event", "node"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |