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