[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yui/src/notification/js/ -> ajaxexception.js (source)

   1  /* global BASE, DIALOGUE_PREFIX */
   2  
   3  /**
   4   * A dialogue type designed to display an appropriate error when an error
   5   * thrown in the Moodle codebase was reported during an AJAX request.
   6   *
   7   * @module moodle-core-notification
   8   * @submodule moodle-core-notification-ajaxexception
   9   */
  10  
  11  var AJAXEXCEPTION_NAME = 'Moodle AJAX exception',
  12      AJAXEXCEPTION;
  13  
  14  /**
  15   * Extends core Dialogue to show the exception dialogue.
  16   *
  17   * @param {Object} config Object literal specifying the dialogue configuration properties.
  18   * @constructor
  19   * @class M.core.ajaxException
  20   * @extends M.core.dialogue
  21   */
  22  AJAXEXCEPTION = function(config) {
  23      config.name = config.name || 'Error';
  24      config.closeButton = true;
  25      AJAXEXCEPTION.superclass.constructor.apply(this, [config]);
  26  };
  27  Y.extend(AJAXEXCEPTION, M.core.notification.info, {
  28      _keypress: null,
  29      initializer: function(config) {
  30          var content,
  31              self = this,
  32              delay = this.get('hideTimeoutDelay');
  33          this.get(BASE).addClass('moodle-dialogue-exception');
  34          this.setStdModContent(Y.WidgetStdMod.HEADER,
  35                  '<h1 id="moodle-dialogue-' + this.get('COUNT') + '-header-text">' + Y.Escape.html(config.name) + '</h1>',
  36                  Y.WidgetStdMod.REPLACE);
  37          content = Y.Node.create('<div class="moodle-ajaxexception"></div>')
  38                  .append(Y.Node.create('<div class="moodle-exception-message">' + Y.Escape.html(this.get('error')) + '</div>'))
  39                  .append(Y.Node.create('<div class="moodle-exception-param hidden param-debuginfo"><label>URL:</label> ' +
  40                          this.get('reproductionlink') + '</div>'))
  41                  .append(Y.Node.create('<div class="moodle-exception-param hidden param-debuginfo"><label>Debug info:</label> ' +
  42                          Y.Escape.html(this.get('debuginfo')) + '</div>'))
  43                  .append(Y.Node.create('<div class="moodle-exception-param hidden param-stacktrace">' +
  44                                        '<label>Stack trace:</label> <pre>' +
  45                          Y.Escape.html(this.get('stacktrace')) + '</pre></div>'));
  46          if (M.cfg.developerdebug) {
  47              content.all('.moodle-exception-param').removeClass('hidden');
  48          }
  49          this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
  50  
  51          if (delay) {
  52              this._hideTimeout = setTimeout(function() {
  53                  self.hide();
  54              }, delay);
  55          }
  56          this.after('visibleChange', this.visibilityChanged, this);
  57          this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this);
  58          this.centerDialogue();
  59      },
  60      visibilityChanged: function(e) {
  61          if (e.attrName === 'visible' && e.prevVal && !e.newVal) {
  62              var self = this;
  63              this._keypress.detach();
  64              setTimeout(function() {
  65                  self.destroy();
  66              }, 1000);
  67          }
  68      }
  69  }, {
  70      NAME: AJAXEXCEPTION_NAME,
  71      CSS_PREFIX: DIALOGUE_PREFIX,
  72      ATTRS: {
  73  
  74          /**
  75           * The error message given in the exception.
  76           *
  77           * @attribute error
  78           * @type String
  79           * @default 'Unknown error'
  80           * @optional
  81           */
  82          error: {
  83              validator: Y.Lang.isString,
  84              value: M.util.get_string('unknownerror', 'moodle')
  85          },
  86  
  87          /**
  88           * Any additional debug information given in the exception.
  89           *
  90           * @attribute stacktrace
  91           * @type String|null
  92           * @default null
  93           * @optional
  94           */
  95          debuginfo: {
  96              value: null
  97          },
  98  
  99          /**
 100           * The complete stack trace provided in the exception.
 101           *
 102           * @attribute stacktrace
 103           * @type String|null
 104           * @default null
 105           * @optional
 106           */
 107          stacktrace: {
 108              value: null
 109          },
 110  
 111          /**
 112           * A link which may be used by support staff to replicate the issue.
 113           *
 114           * @attribute reproductionlink
 115           * @type String
 116           * @default null
 117           * @optional
 118           */
 119          reproductionlink: {
 120              setter: function(link) {
 121                  if (link !== null) {
 122                      link = Y.Escape.html(link);
 123                      link = '<a href="' + link + '">' + link.replace(M.cfg.wwwroot, '') + '</a>';
 124                  }
 125                  return link;
 126              },
 127              value: null
 128          },
 129  
 130          /**
 131           * If set, the dialogue is hidden after the specified timeout period.
 132           *
 133           * @attribute hideTimeoutDelay
 134           * @type Number
 135           * @default null
 136           * @optional
 137           */
 138          hideTimeoutDelay: {
 139              validator: Y.Lang.isNumber,
 140              value: null
 141          }
 142      }
 143  });
 144  
 145  M.core.ajaxException = AJAXEXCEPTION;


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