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