[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/yui/build/moodle-core-notification-ajaxexception/ -> moodle-core-notification-ajaxexception-debug.js (source)

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


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