[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

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

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


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