[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

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


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