[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 /** 2 * JavaScript for form editing completion conditions. 3 * 4 * @module moodle-availability_completion-form 5 */ 6 M.availability_completion = M.availability_completion || {}; 7 8 /** 9 * @class M.availability_completion.form 10 * @extends M.core_availability.plugin 11 */ 12 M.availability_completion.form = Y.Object(M.core_availability.plugin); 13 14 /** 15 * Initialises this plugin. 16 * 17 * @method initInner 18 * @param {Array} cms Array of objects containing cmid => name 19 */ 20 M.availability_completion.form.initInner = function(cms) { 21 this.cms = cms; 22 }; 23 24 M.availability_completion.form.getNode = function(json) { 25 // Create HTML structure. 26 var strings = M.str.availability_completion; 27 var html = strings.title + ' <span class="availability-group"><label>' + 28 '<span class="accesshide">' + strings.label_cm + ' </span>' + 29 '<select name="cm" title="' + strings.label_cm + '">' + 30 '<option value="0">' + M.str.moodle.choosedots + '</option>'; 31 for (var i = 0; i < this.cms.length; i++) { 32 var cm = this.cms[i]; 33 // String has already been escaped using format_string. 34 html += '<option value="' + cm.id + '">' + cm.name + '</option>'; 35 } 36 html += '</select></label> <label><span class="accesshide">' + strings.label_completion + 37 ' </span><select name="e" title="' + strings.label_completion + '">' + 38 '<option value="1">' + strings.option_complete + '</option>' + 39 '<option value="0">' + strings.option_incomplete + '</option>' + 40 '<option value="2">' + strings.option_pass + '</option>' + 41 '<option value="3">' + strings.option_fail + '</option>' + 42 '</select></label></span>'; 43 var node = Y.Node.create('<span>' + html + '</span>'); 44 45 // Set initial values. 46 if (json.cm !== undefined && 47 node.one('select[name=cm] > option[value=' + json.cm + ']')) { 48 node.one('select[name=cm]').set('value', '' + json.cm); 49 } 50 if (json.e !== undefined) { 51 node.one('select[name=e]').set('value', '' + json.e); 52 } 53 54 // Add event handlers (first time only). 55 if (!M.availability_completion.form.addedEvents) { 56 M.availability_completion.form.addedEvents = true; 57 var root = Y.one('#fitem_id_availabilityconditionsjson'); 58 root.delegate('change', function() { 59 // Whichever dropdown changed, just update the form. 60 M.core_availability.form.update(); 61 }, '.availability_completion select'); 62 } 63 64 return node; 65 }; 66 67 M.availability_completion.form.fillValue = function(value, node) { 68 value.cm = parseInt(node.one('select[name=cm]').get('value'), 10); 69 value.e = parseInt(node.one('select[name=e]').get('value'), 10); 70 }; 71 72 M.availability_completion.form.fillErrors = function(errors, node) { 73 var cmid = parseInt(node.one('select[name=cm]').get('value'), 10); 74 if (cmid === 0) { 75 errors.push('availability_completion:error_selectcmid'); 76 } 77 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |