[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/availability/condition/group/yui/src/form/js/ -> form.js (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1