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