[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  /* global BASE, DIALOGUE_PREFIX */
   2  
   3  /**
   4   * A dialogue type designed to display an appropriate error when a generic
   5   * javascript error was thrown and caught.
   6   *
   7   * @module moodle-core-notification
   8   * @submodule moodle-core-notification-exception
   9   */
  10  
  11  var EXCEPTION_NAME = 'Moodle exception',
  12      EXCEPTION;
  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.exception
  20   * @extends M.core.dialogue
  21   */
  22  EXCEPTION = function(c) {
  23      var config = Y.mix({}, c);
  24      config.width = config.width || (M.cfg.developerdebug) ? Math.floor(Y.one(document.body).get('winWidth') / 3) + 'px' : null;
  25      config.closeButton = true;
  26  
  27      // We need to whitelist some properties which are part of the exception
  28      // prototype, otherwise AttributeCore filters them during value normalisation.
  29      var whitelist = [
  30          'message',
  31          'name',
  32          'fileName',
  33          'lineNumber',
  34          'stack'
  35      ];
  36      Y.Array.each(whitelist, function(k) {
  37          config[k] = c[k];
  38      });
  39  
  40      EXCEPTION.superclass.constructor.apply(this, [config]);
  41  };
  42  Y.extend(EXCEPTION, M.core.notification.info, {
  43      _hideTimeout: null,
  44      _keypress: null,
  45      initializer: function(config) {
  46          var content,
  47              self = this,
  48              delay = this.get('hideTimeoutDelay');
  49          this.get(BASE).addClass('moodle-dialogue-exception');
  50          this.setStdModContent(Y.WidgetStdMod.HEADER,
  51                  '<h1 id="moodle-dialogue-' + config.COUNT + '-header-text">' + Y.Escape.html(config.name) + '</h1>',
  52                  Y.WidgetStdMod.REPLACE);
  53          content = Y.Node.create('<div class="moodle-exception"></div>')
  54                  .append(Y.Node.create('<div class="moodle-exception-message">' + Y.Escape.html(this.get('message')) + '</div>'))
  55                  .append(Y.Node.create('<div class="moodle-exception-param hidden param-filename"><label>File:</label> ' +
  56                          Y.Escape.html(this.get('fileName')) + '</div>'))
  57                  .append(Y.Node.create('<div class="moodle-exception-param hidden param-linenumber"><label>Line:</label> ' +
  58                          Y.Escape.html(this.get('lineNumber')) + '</div>'))
  59                  .append(Y.Node.create('<div class="moodle-exception-param hidden param-stacktrace">' +
  60                                        '<label>Stack trace:</label> <pre>' +
  61                          this.get('stack') + '</pre></div>'));
  62          if (M.cfg.developerdebug) {
  63              content.all('.moodle-exception-param').removeClass('hidden');
  64          }
  65          this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
  66  
  67          if (delay) {
  68              this._hideTimeout = setTimeout(function() {
  69                  self.hide();
  70              }, delay);
  71          }
  72          this.after('visibleChange', this.visibilityChanged, this);
  73          this._keypress = Y.on('key', this.hide, window, 'down:13,27', this);
  74          this.centerDialogue();
  75      },
  76      visibilityChanged: function(e) {
  77          if (e.attrName === 'visible' && e.prevVal && !e.newVal) {
  78              if (this._keypress) {
  79                  this._keypress.detach();
  80              }
  81              var self = this;
  82              setTimeout(function() {
  83                  self.destroy();
  84              }, 1000);
  85          }
  86      }
  87  }, {
  88      NAME: EXCEPTION_NAME,
  89      CSS_PREFIX: DIALOGUE_PREFIX,
  90      ATTRS: {
  91          /**
  92           * The message of the alert.
  93           *
  94           * @attribute message
  95           * @type String
  96           * @default ''
  97           */
  98          message: {
  99              value: ''
 100          },
 101  
 102          /**
 103           * The name of the alert.
 104           *
 105           * @attribute title
 106           * @type String
 107           * @default ''
 108           */
 109          name: {
 110              value: ''
 111          },
 112  
 113          /**
 114           * The name of the file where the error was thrown.
 115           *
 116           * @attribute fileName
 117           * @type String
 118           * @default ''
 119           */
 120          fileName: {
 121              value: ''
 122          },
 123  
 124          /**
 125           * The line number where the error was thrown.
 126           *
 127           * @attribute lineNumber
 128           * @type String
 129           * @default ''
 130           */
 131          lineNumber: {
 132              value: ''
 133          },
 134  
 135          /**
 136           * The backtrace from the error
 137           *
 138           * @attribute lineNumber
 139           * @type String
 140           * @default ''
 141           */
 142          stack: {
 143              setter: function(str) {
 144                  var lines = Y.Escape.html(str).split("\n"),
 145                      pattern = new RegExp('^(.+)@(' + M.cfg.wwwroot + ')?(.{0,75}).*:(\\d+)$'),
 146                      i;
 147                  for (i in lines) {
 148                      lines[i] = lines[i].replace(pattern,
 149                              "<div class='stacktrace-line'>ln: $4</div>" +
 150                              "<div class='stacktrace-file'>$3</div>" +
 151                              "<div class='stacktrace-call'>$1</div>");
 152                  }
 153                  return lines.join('');
 154              },
 155              value: ''
 156          },
 157  
 158          /**
 159           * If set, the dialogue is hidden after the specified timeout period.
 160           *
 161           * @attribute hideTimeoutDelay
 162           * @type Number
 163           * @default null
 164           * @optional
 165           */
 166          hideTimeoutDelay: {
 167              validator: Y.Lang.isNumber,
 168              value: null
 169          }
 170      }
 171  });
 172  
 173  M.core.exception = EXCEPTION;


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