Merge branch 'MDL-45381_master' of git://github.com/markn86/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,
62 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + config.name + '</h1>', Y.WidgetStdMod.REPLACE);
63 content = Y.Node.create('<div class="moodle-ajaxexception"></div>')
64 .append(Y.Node.create('<div class="moodle-exception-message">'+this.get('error')+'</div>'))
65 .append(Y.Node.create('<div class="moodle-exception-param hidden param-debuginfo"><label>URL:</label> ' +
66 this.get('reproductionlink')+'</div>'))
67 .append(Y.Node.create('<div class="moodle-exception-param hidden param-debuginfo"><label>Debug info:</label> ' +
68 this.get('debuginfo')+'</div>'))
69 .append(Y.Node.create('<div class="moodle-exception-param hidden param-stacktrace"><label>Stack trace:</label> <pre>' +
70 this.get('stacktrace')+'</pre></div>'));
71 if (M.cfg.developerdebug) {
72 content.all('.moodle-exception-param').removeClass('hidden');
73 }
74 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
75
76 if (delay) {
77 this._hideTimeout = setTimeout(function(){self.hide();}, delay);
78 }
79 this.after('visibleChange', this.visibilityChanged, this);
80 this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this);
81 this.centerDialogue();
82 },
83 visibilityChanged : function(e) {
84 if (e.attrName === 'visible' && e.prevVal && !e.newVal) {
85 var self = this;
86 this._keypress.detach();
87 setTimeout(function(){self.destroy();}, 1000);
88 }
89 }
90}, {
91 NAME : AJAXEXCEPTION_NAME,
92 CSS_PREFIX : DIALOGUE_PREFIX,
93 ATTRS : {
94
95 /**
96 * The error message given in the exception.
97 *
98 * @attribute error
99 * @type String
100 * @default 'Unknown error'
101 * @optional
102 */
103 error : {
104 validator : Y.Lang.isString,
0d1d5423 105 value: M.util.get_string('unknownerror', 'moodle')
78686995
AN
106 },
107
108 /**
109 * Any additional debug information given in the exception.
110 *
111 * @attribute stacktrace
112 * @type String|null
113 * @default null
114 * @optional
115 */
116 debuginfo : {
117 value : null
118 },
119
120 /**
121 * The complete stack trace provided in the exception.
122 *
123 * @attribute stacktrace
124 * @type String|null
125 * @default null
126 * @optional
127 */
128 stacktrace : {
129 value : null
130 },
131
132 /**
133 * A link which may be used by support staff to replicate the issue.
134 *
135 * @attribute reproductionlink
136 * @type String
137 * @default null
138 * @optional
139 */
140 reproductionlink : {
141 setter : function(link) {
142 if (link !== null) {
143 link = '<a href="'+link+'">'+link.replace(M.cfg.wwwroot, '')+'</a>';
144 }
145 return link;
146 },
147 value : null
148 },
149
150 /**
151 * If set, the dialogue is hidden after the specified timeout period.
152 *
153 * @attribute hideTimeoutDelay
154 * @type Number
155 * @default null
156 * @optional
157 */
158 hideTimeoutDelay : {
159 validator : Y.Lang.isNumber,
160 value : null
161 }
162 }
163});
164
165M.core.ajaxException = AJAXEXCEPTION;
166
167
168}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});