MDL-45758 tool_monitor: YUI module to handle event selection dropdown

Original issue - MDL-45938
This commit is contained in:
Ankit Agarwal 2014-07-10 14:48:37 +08:00
parent 48cc3a8d4d
commit 2fd010b886
6 changed files with 291 additions and 0 deletions

View File

@ -0,0 +1,92 @@
YUI.add('moodle-tool_monitor-dropdown', function (Y, NAME) {
/**
* A module to manage dropdowns on the rule add/edit form.
*
* @module moodle-tool_monitor-dropdown
*/
/**
* A module to manage dependent selects on the edit page.
*
* @since Moodle 2.8
* @class moodle-tool_monitor.dropdown
* @extends Base
* @constructor
*/
function DropDown() {
DropDown.superclass.constructor.apply(this, arguments);
}
var SELECTORS = {
PLUGIN: '#id_plugin',
EVENTNAME: '#id_eventname',
OPTION: 'option',
CHOOSE: 'option[value=""]'
};
Y.extend(DropDown, Y.Base, {
/**
* Reference to the plugin node.
*
* @property plugin
* @type Object
* @default null
* @protected
*/
plugin: null,
/**
* Reference to the plugin node.
*
* @property eventname
* @type Object
* @default null
* @protected
*/
eventname: null,
/**
* Initializer.
* Basic setup and delegations.
*
* @method initializer
*/
initializer: function() {
this.plugin = Y.one(SELECTORS.PLUGIN);
this.eventname = Y.one(SELECTORS.EVENTNAME);
this.plugin.on('change', this.updateEventsList, this);
},
/**
* Method to update the events list drop down when plugin list drop down is changed.
*
* @method updateEventsList
*/
updateEventsList: function() {
var plugin = this.plugin.get('value'); // Get component name.
var namespace = '\\' + plugin + '\\';
this.eventname.all(SELECTORS.OPTION).hide(); // Hide all options.
this.eventname.all(SELECTORS.OPTION).each(function(node) {
// Make sure we highlight only nodes with correct namespace.
if (node.get('value').substring(0, namespace.length) === namespace) {
node.show();
}
});
// Mark the default choose node as visible and selected.
var choosenode = this.eventname.one(SELECTORS.CHOOSE);
choosenode.show().set('selected', 'selected');
}
}, {
NAME: 'dropDown',
ATTRS: {}
});
Y.namespace('M.tool_monitor.DropDown').init = function(config) {
return new DropDown(config);
};
}, '@VERSION@', {"requires": ["base", "event", "node"]});

View File

@ -0,0 +1 @@
YUI.add("moodle-tool_monitor-dropdown",function(e,t){function n(){n.superclass.constructor.apply(this,arguments)}var r={PLUGIN:"#id_plugin",EVENTNAME:"#id_eventname",OPTION:"option",CHOOSE:'option[value=""]'};e.extend(n,e.Base,{plugin:null,eventname:null,initializer:function(){this.plugin=e.one(r.PLUGIN),this.eventname=e.one(r.EVENTNAME),this.plugin.on("change",this.updateEventsList,this)},updateEventsList:function(){var e=this.plugin.get("value"),t="\\"+e+"\\";this.eventname.all(r.OPTION).hide(),this.eventname.all(r.OPTION).each(function(e){e.get("value").substring(0,t.length)===t&&e.show()});var n=this.eventname.one(r.CHOOSE);n.show().set("selected","selected")}},{NAME:"dropDown",ATTRS:{}}),e.namespace("M.tool_monitor.DropDown").init=function(e){return new n(e)}},"@VERSION@",{requires:["base","event","node"]});

View File

@ -0,0 +1,92 @@
YUI.add('moodle-tool_monitor-dropdown', function (Y, NAME) {
/**
* A module to manage dropdowns on the rule add/edit form.
*
* @module moodle-tool_monitor-dropdown
*/
/**
* A module to manage dependent selects on the edit page.
*
* @since Moodle 2.8
* @class moodle-tool_monitor.dropdown
* @extends Base
* @constructor
*/
function DropDown() {
DropDown.superclass.constructor.apply(this, arguments);
}
var SELECTORS = {
PLUGIN: '#id_plugin',
EVENTNAME: '#id_eventname',
OPTION: 'option',
CHOOSE: 'option[value=""]'
};
Y.extend(DropDown, Y.Base, {
/**
* Reference to the plugin node.
*
* @property plugin
* @type Object
* @default null
* @protected
*/
plugin: null,
/**
* Reference to the plugin node.
*
* @property eventname
* @type Object
* @default null
* @protected
*/
eventname: null,
/**
* Initializer.
* Basic setup and delegations.
*
* @method initializer
*/
initializer: function() {
this.plugin = Y.one(SELECTORS.PLUGIN);
this.eventname = Y.one(SELECTORS.EVENTNAME);
this.plugin.on('change', this.updateEventsList, this);
},
/**
* Method to update the events list drop down when plugin list drop down is changed.
*
* @method updateEventsList
*/
updateEventsList: function() {
var plugin = this.plugin.get('value'); // Get component name.
var namespace = '\\' + plugin + '\\';
this.eventname.all(SELECTORS.OPTION).hide(); // Hide all options.
this.eventname.all(SELECTORS.OPTION).each(function(node) {
// Make sure we highlight only nodes with correct namespace.
if (node.get('value').substring(0, namespace.length) === namespace) {
node.show();
}
});
// Mark the default choose node as visible and selected.
var choosenode = this.eventname.one(SELECTORS.CHOOSE);
choosenode.show().set('selected', 'selected');
}
}, {
NAME: 'dropDown',
ATTRS: {}
});
Y.namespace('M.tool_monitor.DropDown').init = function(config) {
return new DropDown(config);
};
}, '@VERSION@', {"requires": ["base", "event", "node"]});

View File

@ -0,0 +1,10 @@
{
"name": "moodle-tool_monitor-dropdown",
"builds": {
"moodle-tool_monitor-dropdown": {
"jsfiles": [
"dropdown.js"
]
}
}
}

View File

@ -0,0 +1,87 @@
/**
* A module to manage dropdowns on the rule add/edit form.
*
* @module moodle-tool_monitor-dropdown
*/
/**
* A module to manage dependent selects on the edit page.
*
* @since Moodle 2.8
* @class moodle-tool_monitor.dropdown
* @extends Base
* @constructor
*/
function DropDown() {
DropDown.superclass.constructor.apply(this, arguments);
}
var SELECTORS = {
PLUGIN: '#id_plugin',
EVENTNAME: '#id_eventname',
OPTION: 'option',
CHOOSE: 'option[value=""]'
};
Y.extend(DropDown, Y.Base, {
/**
* Reference to the plugin node.
*
* @property plugin
* @type Object
* @default null
* @protected
*/
plugin: null,
/**
* Reference to the plugin node.
*
* @property eventname
* @type Object
* @default null
* @protected
*/
eventname: null,
/**
* Initializer.
* Basic setup and delegations.
*
* @method initializer
*/
initializer: function() {
this.plugin = Y.one(SELECTORS.PLUGIN);
this.eventname = Y.one(SELECTORS.EVENTNAME);
this.plugin.on('change', this.updateEventsList, this);
},
/**
* Method to update the events list drop down when plugin list drop down is changed.
*
* @method updateEventsList
*/
updateEventsList: function() {
var plugin = this.plugin.get('value'); // Get component name.
var namespace = '\\' + plugin + '\\';
this.eventname.all(SELECTORS.OPTION).hide(); // Hide all options.
this.eventname.all(SELECTORS.OPTION).each(function(node) {
// Make sure we highlight only nodes with correct namespace.
if (node.get('value').substring(0, namespace.length) === namespace) {
node.show();
}
});
// Mark the default choose node as visible and selected.
var choosenode = this.eventname.one(SELECTORS.CHOOSE);
choosenode.show().set('selected', 'selected');
}
}, {
NAME: 'dropDown',
ATTRS: {}
});
Y.namespace('M.tool_monitor.DropDown').init = function(config) {
return new DropDown(config);
};

View File

@ -0,0 +1,9 @@
{
"moodle-tool_monitor-dropdown": {
"requires": [
"base",
"event",
"node"
]
}
}