[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/course/yui/src/toolboxes/js/ -> toolbox.js (source)

   1  /**
   2   * Resource and activity toolbox class.
   3   *
   4   * This class is responsible for managing AJAX interactions with activities and resources
   5   * when viewing a course in editing mode.
   6   *
   7   * @module moodle-course-toolboxes
   8   * @namespace M.course.toolboxes
   9   */
  10  
  11  // The CSS classes we use.
  12  var CSS = {
  13          ACTIVITYINSTANCE : 'activityinstance',
  14          AVAILABILITYINFODIV : 'div.availabilityinfo',
  15          CONTENTWITHOUTLINK : 'contentwithoutlink',
  16          CONDITIONALHIDDEN : 'conditionalhidden',
  17          DIMCLASS : 'dimmed',
  18          DIMMEDTEXT : 'dimmed_text',
  19          EDITINSTRUCTIONS : 'editinstructions',
  20          EDITINGTITLE: 'editor_displayed',
  21          HIDE : 'hide',
  22          MODINDENTCOUNT : 'mod-indent-',
  23          MODINDENTHUGE : 'mod-indent-huge',
  24          MODULEIDPREFIX : 'module-',
  25          SECTIONHIDDENCLASS : 'hidden',
  26          SECTIONIDPREFIX : 'section-',
  27          SHOW : 'editing_show',
  28          TITLEEDITOR : 'titleeditor'
  29      },
  30      // The CSS selectors we use.
  31      SELECTOR = {
  32          ACTIONAREA: '.actions',
  33          ACTIONLINKTEXT : '.actionlinktext',
  34          ACTIVITYACTION : 'a.cm-edit-action[data-action], a.editing_title',
  35          ACTIVITYFORM : '.' + CSS.ACTIVITYINSTANCE + ' form',
  36          ACTIVITYICON : 'img.activityicon',
  37          ACTIVITYINSTANCE : '.' + CSS.ACTIVITYINSTANCE,
  38          ACTIVITYLINK: '.' + CSS.ACTIVITYINSTANCE + ' > a',
  39          ACTIVITYLI : 'li.activity',
  40          ACTIVITYTITLE : 'input[name=title]',
  41          COMMANDSPAN : '.commands',
  42          CONTENTAFTERLINK : 'div.contentafterlink',
  43          CONTENTWITHOUTLINK : 'div.contentwithoutlink',
  44          EDITTITLE: 'a.editing_title',
  45          HIDE : 'a.editing_hide',
  46          HIGHLIGHT : 'a.editing_highlight',
  47          INSTANCENAME : 'span.instancename',
  48          MODINDENTDIV : '.mod-indent',
  49          MODINDENTOUTER : '.mod-indent-outer',
  50          PAGECONTENT : 'body',
  51          SECTIONLI : 'li.section',
  52          SHOW : 'a.'+CSS.SHOW,
  53          SHOWHIDE : 'a.editing_showhide'
  54      },
  55      INDENTLIMITS = {
  56          MIN: 0,
  57          MAX: 16
  58      },
  59      BODY = Y.one(document.body);
  60  
  61  // Setup the basic namespace.
  62  M.course = M.course || {};
  63  
  64  /**
  65   * The toolbox class is a generic class which should never be directly
  66   * instantiated. Please extend it instead.
  67   *
  68   * @class toolbox
  69   * @constructor
  70   * @protected
  71   * @extends Base
  72   */
  73  var TOOLBOX = function() {
  74      TOOLBOX.superclass.constructor.apply(this, arguments);
  75  };
  76  
  77  Y.extend(TOOLBOX, Y.Base, {
  78      /**
  79       * Send a request using the REST API
  80       *
  81       * @method send_request
  82       * @param {Object} data The data to submit with the AJAX request
  83       * @param {Node} [statusspinner] A statusspinner which may contain a section loader
  84       * @param {Function} success_callback The callback to use on success
  85       * @param {Object} [optionalconfig] Any additional configuration to submit
  86       * @chainable
  87       */
  88      send_request: function(data, statusspinner, success_callback, optionalconfig) {
  89          // Default data structure
  90          if (!data) {
  91              data = {};
  92          }
  93          // Handle any variables which we must pass back through to
  94          var pageparams = this.get('config').pageparams,
  95              varname;
  96          for (varname in pageparams) {
  97              data[varname] = pageparams[varname];
  98          }
  99  
 100          data.sesskey = M.cfg.sesskey;
 101          data.courseId = this.get('courseid');
 102  
 103          var uri = M.cfg.wwwroot + this.get('ajaxurl');
 104  
 105          // Define the configuration to send with the request
 106          var responsetext = [];
 107          var config = {
 108              method: 'POST',
 109              data: data,
 110              on: {
 111                  success: function(tid, response) {
 112                      try {
 113                          responsetext = Y.JSON.parse(response.responseText);
 114                          if (responsetext.error) {
 115                              new M.core.ajaxException(responsetext);
 116                          }
 117                      } catch (e) {}
 118  
 119                      // Run the callback if we have one.
 120                      if (success_callback) {
 121                          Y.bind(success_callback, this, responsetext)();
 122                      }
 123  
 124                      if (statusspinner) {
 125                          window.setTimeout(function() {
 126                              statusspinner.hide();
 127                          }, 400);
 128                      }
 129                  },
 130                  failure: function(tid, response) {
 131                      if (statusspinner) {
 132                          statusspinner.hide();
 133                      }
 134                      new M.core.ajaxException(response);
 135                  }
 136              },
 137              context: this
 138          };
 139  
 140          // Apply optional config
 141          if (optionalconfig) {
 142              for (varname in optionalconfig) {
 143                  config[varname] = optionalconfig[varname];
 144              }
 145          }
 146  
 147          if (statusspinner) {
 148              statusspinner.show();
 149          }
 150  
 151          // Send the request
 152          Y.io(uri, config);
 153          return this;
 154      }
 155  },
 156  {
 157      NAME: 'course-toolbox',
 158      ATTRS: {
 159          /**
 160           * The ID of the Moodle Course being edited.
 161           *
 162           * @attribute courseid
 163           * @default 0
 164           * @type Number
 165           */
 166          courseid: {
 167              'value': 0
 168          },
 169  
 170          /**
 171           * The Moodle course format.
 172           *
 173           * @attribute format
 174           * @default 'topics'
 175           * @type String
 176           */
 177          format: {
 178              'value': 'topics'
 179          },
 180          /**
 181           * The URL to use when submitting requests.
 182           * @attribute ajaxurl
 183           * @default null
 184           * @type String
 185           */
 186          ajaxurl: {
 187              'value': null
 188          },
 189          /**
 190           * Any additional configuration passed when creating the instance.
 191           *
 192           * @attribute config
 193           * @default {}
 194           * @type Object
 195           */
 196          config: {
 197              'value': {}
 198          }
 199      }
 200  }
 201  );
 202  


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