[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-availability_profile-form', function (Y, NAME) { 2 3 /** 4 * JavaScript for form editing profile conditions. 5 * 6 * @module moodle-availability_profile-form 7 */ 8 M.availability_profile = M.availability_profile || {}; 9 10 /** 11 * @class M.availability_profile.form 12 * @extends M.core_availability.plugin 13 */ 14 M.availability_profile.form = Y.Object(M.core_availability.plugin); 15 16 /** 17 * Groupings available for selection (alphabetical order). 18 * 19 * @property profiles 20 * @type Array 21 */ 22 M.availability_profile.form.profiles = null; 23 24 /** 25 * Initialises this plugin. 26 * 27 * @method initInner 28 * @param {Array} standardFields Array of objects with .field, .display 29 * @param {Array} customFields Array of objects with .field, .display 30 */ 31 M.availability_profile.form.initInner = function(standardFields, customFields) { 32 this.standardFields = standardFields; 33 this.customFields = customFields; 34 }; 35 36 M.availability_profile.form.getNode = function(json) { 37 // Create HTML structure. 38 var html = '<span class="availability-group"><label>' + M.util.get_string('conditiontitle', 'availability_profile') + ' ' + 39 '<select name="field">' + 40 '<option value="choose">' + M.util.get_string('choosedots', 'moodle') + '</option>'; 41 var fieldInfo; 42 for (var i = 0; i < this.standardFields.length; i++) { 43 fieldInfo = this.standardFields[i]; 44 // String has already been escaped using format_string. 45 html += '<option value="sf_' + fieldInfo.field + '">' + fieldInfo.display + '</option>'; 46 } 47 for (i = 0; i < this.customFields.length; i++) { 48 fieldInfo = this.customFields[i]; 49 // String has already been escaped using format_string. 50 html += '<option value="cf_' + fieldInfo.field + '">' + fieldInfo.display + '</option>'; 51 } 52 html += '</select></label> <label><span class="accesshide">' + M.util.get_string('label_operator', 'availability_profile') + 53 ' </span><select name="op" title="' + M.util.get_string('label_operator', 'availability_profile') + '">'; 54 var operators = ['isequalto', 'contains', 'doesnotcontain', 'startswith', 'endswith', 55 'isempty', 'isnotempty']; 56 for (i = 0; i < operators.length; i++) { 57 html += '<option value="' + operators[i] + '">' + 58 M.util.get_string('op_' + operators[i], 'availability_profile') + '</option>'; 59 } 60 html += '</select></label> <label><span class="accesshide">' + M.util.get_string('label_value', 'availability_profile') + 61 '</span><input name="value" type="text" style="width: 10em" title="' + 62 M.util.get_string('label_value', 'availability_profile') + '"/></label></span>'; 63 var node = Y.Node.create('<span>' + html + '</span>'); 64 65 // Set initial values if specified. 66 if (json.sf !== undefined && 67 node.one('select[name=field] > option[value=sf_' + json.sf + ']')) { 68 node.one('select[name=field]').set('value', 'sf_' + json.sf); 69 } else if (json.cf !== undefined && 70 node.one('select[name=field] > option[value=cf_' + json.cf + ']')) { 71 node.one('select[name=field]').set('value', 'cf_' + json.cf); 72 } 73 if (json.op !== undefined && 74 node.one('select[name=op] > option[value=' + json.op + ']')) { 75 node.one('select[name=op]').set('value', json.op); 76 if (json.op === 'isempty' || json.op === 'isnotempty') { 77 node.one('input[name=value]').set('disabled', true); 78 } 79 } 80 if (json.v !== undefined) { 81 node.one('input').set('value', json.v); 82 } 83 84 // Add event handlers (first time only). 85 if (!M.availability_profile.form.addedEvents) { 86 M.availability_profile.form.addedEvents = true; 87 var updateForm = function(input) { 88 var ancestorNode = input.ancestor('span.availability_profile'); 89 var op = ancestorNode.one('select[name=op]'); 90 var novalue = (op.get('value') === 'isempty' || op.get('value') === 'isnotempty'); 91 ancestorNode.one('input[name=value]').set('disabled', novalue); 92 M.core_availability.form.update(); 93 }; 94 var root = Y.one('#fitem_id_availabilityconditionsjson'); 95 root.delegate('change', function() { 96 updateForm(this); 97 }, '.availability_profile select'); 98 root.delegate('change', function() { 99 updateForm(this); 100 }, '.availability_profile input[name=value]'); 101 } 102 103 return node; 104 }; 105 106 M.availability_profile.form.fillValue = function(value, node) { 107 // Set field. 108 var field = node.one('select[name=field]').get('value'); 109 if (field.substr(0, 3) === 'sf_') { 110 value.sf = field.substr(3); 111 } else if (field.substr(0, 3) === 'cf_') { 112 value.cf = field.substr(3); 113 } 114 115 // Operator and value 116 value.op = node.one('select[name=op]').get('value'); 117 var valueNode = node.one('input[name=value]'); 118 if (!valueNode.get('disabled')) { 119 value.v = valueNode.get('value'); 120 } 121 }; 122 123 M.availability_profile.form.fillErrors = function(errors, node) { 124 var value = {}; 125 this.fillValue(value, node); 126 127 // Check profile item id. 128 if (value.sf === undefined && value.cf === undefined) { 129 errors.push('availability_profile:error_selectfield'); 130 } 131 if (value.v !== undefined && /^\s*$/.test(value.v)) { 132 errors.push('availability_profile:error_setvalue'); 133 } 134 }; 135 136 137 }, '@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 |