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