[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/amd/src/ -> competency_rule.js (source)

   1  // This file is part of Moodle - http://moodle.org/
   2  //
   3  // Moodle is free software: you can redistribute it and/or modify
   4  // it under the terms of the GNU General Public License as published by
   5  // the Free Software Foundation, either version 3 of the License, or
   6  // (at your option) any later version.
   7  //
   8  // Moodle is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU General Public License for more details.
  12  //
  13  // You should have received a copy of the GNU General Public License
  14  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  15  
  16  /**
  17   * Competency rule base module.
  18   *
  19   * @package    tool_lp
  20   * @copyright  2015 Frédéric Massart - FMCorz.net
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  define(['jquery'], function($) {
  25  
  26      /**
  27       * Competency rule abstract class.
  28       *
  29       * Any competency rule should extend this object. The event 'change' should be
  30       * triggered on the instance when the configuration has changed. This will allow
  31       * the components using the rule to gather the config, or check its validity.
  32       *
  33       * this._triggerChange();
  34       *
  35       * @param {Tree} tree The competency tree.
  36       */
  37      var Rule = function(tree) {
  38          this._eventNode = $('<div>');
  39          this._ready = $.Deferred();
  40          this._tree = tree;
  41      };
  42  
  43      /** @type {Object} The current competency. */
  44      Rule.prototype._competency = null;
  45      /** @type {Node} The node we attach the events to. */
  46      Rule.prototype._eventNode = null;
  47      /** @type {Promise} Resolved when the object is ready. */
  48      Rule.prototype._ready = null;
  49      /** @type {Tree} The competency tree. */
  50      Rule.prototype._tree = null;
  51  
  52      /**
  53       * Whether or not the current competency can be configured using this rule.
  54       *
  55       * @return {Boolean}
  56       * @method canConfig
  57       */
  58      Rule.prototype.canConfig = function() {
  59          return this._tree.hasChildren(this._competency.id);
  60      };
  61  
  62      /**
  63       * The config established by this rule.
  64       *
  65       * To override in subclasses when relevant.
  66       *
  67       * @return {String|null}
  68       * @method getConfig
  69       */
  70      Rule.prototype.getConfig = function() {
  71          return null;
  72      };
  73  
  74      // eslint-disable-next-line valid-jsdoc
  75      /**
  76       * Return the type of the module.
  77       *
  78       * @return {String}
  79       * @method getType
  80       */
  81      Rule.prototype.getType = function() {
  82          throw new Error('Not implemented');
  83      };
  84  
  85      /**
  86       * The init process.
  87       *
  88       * Do not override this, instead override _load.
  89       *
  90       * @return {Promise} Revoled when the plugin is initialised.
  91       * @method init
  92       */
  93      Rule.prototype.init = function() {
  94          return this._load();
  95      };
  96  
  97      /**
  98       * Callback to inject the template.
  99       *
 100       * @param  {Node} container Node to inject in.
 101       * @return {Promise} Resolved when done.
 102       * @method injectTemplate
 103       */
 104      Rule.prototype.injectTemplate = function() {
 105          return $.Deferred().reject().promise();
 106      };
 107  
 108      /**
 109       * Whether or not the current config is valid.
 110       *
 111       * Plugins should override this.
 112       *
 113       * @return {Boolean}
 114       * @method _isValid
 115       */
 116      Rule.prototype.isValid = function() {
 117          return false;
 118      };
 119  
 120      /**
 121       * Load the class.
 122       *
 123       * @return {Promise}
 124       * @method _load
 125       * @protected
 126       */
 127      Rule.prototype._load = function() {
 128          return $.when();
 129      };
 130  
 131      /**
 132       * Register an event listener.
 133       *
 134       * @param {String} type The event type.
 135       * @param {Function} handler The event listener.
 136       * @method on
 137       */
 138      Rule.prototype.on = function(type, handler) {
 139          this._eventNode.on(type, handler);
 140      };
 141  
 142      /**
 143       * Sets the current competency.
 144       *
 145       * @param {Competency} competency
 146       * @method setTargetCompetency
 147       */
 148      Rule.prototype.setTargetCompetency = function(competency) {
 149          this._competency = competency;
 150      };
 151  
 152      /**
 153       * Trigger an event.
 154       *
 155       * @param {String} type The type of event.
 156       * @param {Object} data The data to pass to the listeners.
 157       * @method _trigger
 158       * @protected
 159       */
 160      Rule.prototype._trigger = function(type, data) {
 161          this._eventNode.trigger(type, [data]);
 162      };
 163  
 164      /**
 165       * Trigger the change event.
 166       *
 167       * @method _triggerChange
 168       * @protected
 169       */
 170      Rule.prototype._triggerChange = function() {
 171          this._trigger('change', this);
 172      };
 173  
 174      return /** @alias module:tool_lp/competency_rule */ Rule;
 175  
 176  });


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