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