[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-availability_grouping-form', function (Y, NAME) { 2 3 /** 4 * JavaScript for form editing grouping conditions. 5 * 6 * @module moodle-availability_grouping-form 7 */ 8 M.availability_grouping = M.availability_grouping || {}; 9 10 /** 11 * @class M.availability_grouping.form 12 * @extends M.core_availability.plugin 13 */ 14 M.availability_grouping.form = Y.Object(M.core_availability.plugin); 15 16 /** 17 * Groupings available for selection (alphabetical order). 18 * 19 * @property groupings 20 * @type Array 21 */ 22 M.availability_grouping.form.groupings = null; 23 24 /** 25 * Initialises this plugin. 26 * 27 * @method initInner 28 * @param {Array} groupings Array of objects containing groupingid => name 29 */ 30 M.availability_grouping.form.initInner = function(groupings) { 31 this.groupings = groupings; 32 }; 33 34 M.availability_grouping.form.getNode = function(json) { 35 // Create HTML structure. 36 var html = '<label>' + M.util.get_string('title', 'availability_grouping') + ' <span class="availability-group">' + 37 '<select name="id">' + 38 '<option value="choose">' + M.util.get_string('choosedots', 'moodle') + '</option>'; 39 for (var i = 0; i < this.groupings.length; i++) { 40 var grouping = this.groupings[i]; 41 // String has already been escaped using format_string. 42 html += '<option value="' + grouping.id + '">' + grouping.name + '</option>'; 43 } 44 html += '</select></span></label>'; 45 var node = Y.Node.create('<span>' + html + '</span>'); 46 47 // Set initial value if specified. 48 if (json.id !== undefined && 49 node.one('select[name=id] > option[value=' + json.id + ']')) { 50 node.one('select[name=id]').set('value', '' + json.id); 51 } 52 53 // Add event handlers (first time only). 54 if (!M.availability_grouping.form.addedEvents) { 55 M.availability_grouping.form.addedEvents = true; 56 var root = Y.one('#fitem_id_availabilityconditionsjson'); 57 root.delegate('change', function() { 58 // Just update the form fields. 59 M.core_availability.form.update(); 60 }, '.availability_grouping select'); 61 } 62 63 return node; 64 }; 65 66 M.availability_grouping.form.fillValue = function(value, node) { 67 var selected = node.one('select[name=id]').get('value'); 68 if (selected === 'choose') { 69 value.id = 'choose'; 70 } else { 71 value.id = parseInt(selected, 10); 72 } 73 }; 74 75 M.availability_grouping.form.fillErrors = function(errors, node) { 76 var value = {}; 77 this.fillValue(value, node); 78 79 // Check grouping item id. 80 if (value.id === 'choose') { 81 errors.push('availability_grouping:error_selectgrouping'); 82 } 83 }; 84 85 86 }, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]});
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 |