[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/course/yui/src/modchooser/js/ -> modchooser.js (source)

   1  /**
   2   * The activity chooser dialogue for courses.
   3   *
   4   * @module moodle-course-modchooser
   5   */
   6  
   7  var CSS = {
   8      PAGECONTENT: 'body',
   9      SECTION: null,
  10      SECTIONMODCHOOSER: 'span.section-modchooser-link',
  11      SITEMENU: 'div.block_site_main_menu',
  12      SITETOPIC: 'div.sitetopic'
  13  };
  14  
  15  var MODCHOOSERNAME = 'course-modchooser';
  16  
  17  /**
  18   * The activity chooser dialogue for courses.
  19   *
  20   * @constructor
  21   * @class M.course.modchooser
  22   * @extends M.core.chooserdialogue
  23   */
  24  var MODCHOOSER = function() {
  25      MODCHOOSER.superclass.constructor.apply(this, arguments);
  26  };
  27  
  28  Y.extend(MODCHOOSER, M.core.chooserdialogue, {
  29      /**
  30       * The current section ID.
  31       *
  32       * @property sectionid
  33       * @private
  34       * @type Number
  35       * @default null
  36       */
  37      sectionid: null,
  38  
  39      /**
  40       * Set up the activity chooser.
  41       *
  42       * @method initializer
  43       */
  44      initializer: function() {
  45          var sectionclass = M.course.format.get_sectionwrapperclass();
  46          if (sectionclass) {
  47              CSS.SECTION = '.' + sectionclass;
  48          }
  49          var dialogue = Y.one('.chooserdialoguebody');
  50          var header = Y.one('.choosertitle');
  51          var params = {};
  52          this.setup_chooser_dialogue(dialogue, header, params);
  53  
  54          // Initialize existing sections and register for dynamically created sections
  55          this.setup_for_section();
  56          M.course.coursebase.register_module(this);
  57      },
  58  
  59      /**
  60       * Update any section areas within the scope of the specified
  61       * selector with AJAX equivalents
  62       *
  63       * @method setup_for_section
  64       * @param baseselector The selector to limit scope to
  65       */
  66      setup_for_section: function(baseselector) {
  67          if (!baseselector) {
  68              baseselector = CSS.PAGECONTENT;
  69          }
  70  
  71          // Setup for site topics
  72          Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
  73              this._setup_for_section(section);
  74          }, this);
  75  
  76          // Setup for standard course topics
  77          if (CSS.SECTION) {
  78              Y.one(baseselector).all(CSS.SECTION).each(function(section) {
  79                  this._setup_for_section(section);
  80              }, this);
  81          }
  82  
  83          // Setup for the block site menu
  84          Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
  85              this._setup_for_section(section);
  86          }, this);
  87      },
  88  
  89      /**
  90       * Update any section areas within the scope of the specified
  91       * selector with AJAX equivalents
  92       *
  93       * @method _setup_for_section
  94       * @private
  95       * @param baseselector The selector to limit scope to
  96       */
  97      _setup_for_section: function(section) {
  98          var chooserspan = section.one(CSS.SECTIONMODCHOOSER);
  99          if (!chooserspan) {
 100              return;
 101          }
 102          var chooserlink = Y.Node.create("<a href='#' />");
 103          chooserspan.get('children').each(function(node) {
 104              chooserlink.appendChild(node);
 105          });
 106          chooserspan.insertBefore(chooserlink);
 107          chooserlink.on('click', this.display_mod_chooser, this);
 108      },
 109      /**
 110       * Display the module chooser
 111       *
 112       * @method display_mod_chooser
 113       * @param {EventFacade} e Triggering Event
 114       */
 115      display_mod_chooser: function(e) {
 116          // Set the section for this version of the dialogue
 117          if (e.target.ancestor(CSS.SITETOPIC)) {
 118              // The site topic has a sectionid of 1
 119              this.sectionid = 1;
 120          } else if (e.target.ancestor(CSS.SECTION)) {
 121              var section = e.target.ancestor(CSS.SECTION);
 122              this.sectionid = section.get('id').replace('section-', '');
 123          } else if (e.target.ancestor(CSS.SITEMENU)) {
 124              // The block site menu has a sectionid of 0
 125              this.sectionid = 0;
 126          }
 127          this.display_chooser(e);
 128      },
 129  
 130      /**
 131       * Helper function to set the value of a hidden radio button when a
 132       * selection is made.
 133       *
 134       * @method option_selected
 135       * @param {String} thisoption The selected option value
 136       * @private
 137       */
 138      option_selected: function(thisoption) {
 139          // Add the sectionid to the URL.
 140          this.hiddenRadioValue.setAttrs({
 141              name: 'jump',
 142              value: thisoption.get('value') + '&section=' + this.sectionid
 143          });
 144      }
 145  },
 146  {
 147      NAME: MODCHOOSERNAME,
 148      ATTRS: {
 149          /**
 150           * The maximum height (in pixels) of the activity chooser.
 151           *
 152           * @attribute maxheight
 153           * @type Number
 154           * @default 800
 155           */
 156          maxheight: {
 157              value: 800
 158          }
 159      }
 160  });
 161  M.course = M.course || {};
 162  M.course.init_chooser = function(config) {
 163      return new MODCHOOSER(config);
 164  };


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