[ Index ]

PHP Cross Reference of moodle-2.8

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 strings = M.str.availability_group;
  35      var html = '<label>' + strings.title + ' <span class="availability-group">' +
  36              '<select name="id">' +
  37              '<option value="choose">' + M.str.moodle.choosedots + '</option>' +
  38              '<option value="any">' + strings.anygroup + '</option>';
  39      for (var i = 0; i < this.groups.length; i++) {
  40          var group = this.groups[i];
  41          // String has already been escaped using format_string.
  42          html += '<option value="' + group.id + '">' + group.name + '</option>';
  43      }
  44      html += '</select></span></label>';
  45      var node = Y.Node.create('<span>' + html + '</span>');
  46  
  47      // Set initial values (leave default 'choose' if creating afresh).
  48      if (json.creating === undefined) {
  49          if (json.id !== undefined &&
  50                  node.one('select[name=id] > option[value=' + json.id + ']')) {
  51              node.one('select[name=id]').set('value', '' + json.id);
  52          } else if (json.id === undefined) {
  53              node.one('select[name=id]').set('value', 'any');
  54          }
  55      }
  56  
  57      // Add event handlers (first time only).
  58      if (!M.availability_group.form.addedEvents) {
  59          M.availability_group.form.addedEvents = true;
  60          var root = Y.one('#fitem_id_availabilityconditionsjson');
  61          root.delegate('change', function() {
  62              // Just update the form fields.
  63              M.core_availability.form.update();
  64          }, '.availability_group select');
  65      }
  66  
  67      return node;
  68  };
  69  
  70  M.availability_group.form.fillValue = function(value, node) {
  71      var selected = node.one('select[name=id]').get('value');
  72      if (selected === 'choose') {
  73          value.id = 'choose';
  74      } else if (selected !== 'any') {
  75          value.id = parseInt(selected, 10);
  76      }
  77  };
  78  
  79  M.availability_group.form.fillErrors = function(errors, node) {
  80      var value = {};
  81      this.fillValue(value, node);
  82  
  83      // Check group item id.
  84      if (value.id && value.id === 'choose') {
  85          errors.push('availability_group:error_selectgroup');
  86      }
  87  };


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1