[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

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


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