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