mirrored from git://git.moodle.org/moodle.git
/
alert.js
117 lines (108 loc) · 3.34 KB
/
alert.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
/* global BASE, TITLE, CONFIRMYES, DIALOGUE_PREFIX */
/**
* A dialogue type designed to display an alert to the user.
*
* @module moodle-core-notification
* @submodule moodle-core-notification-alert
*/
var ALERT_NAME = 'Moodle alert',
ALERT;
/**
* Extends core Dialogue to show the alert dialogue.
*
* @param {Object} config Object literal specifying the dialogue configuration properties.
* @constructor
* @class M.core.alert
* @extends M.core.dialogue
*/
ALERT = function(config) {
config.closeButton = false;
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, M.core.notification.info, {
/**
* The list of events to detach when destroying this dialogue.
*
* @property _closeEvents
* @type EventHandle[]
* @private
*/
_closeEvents: null,
initializer: function() {
this._closeEvents = [];
this.publish('complete');
var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '"' +
'value="' + this.get(CONFIRMYES) + '" />'),
content = Y.Node.create('<div class="confirmation-dialogue"></div>')
.append(Y.Node.create('<div class="confirmation-message">' + this.get('message') + '</div>'))
.append(Y.Node.create('<div class="confirmation-buttons"></div>')
.append(yes));
this.get(BASE).addClass('moodle-dialogue-confirm');
this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
this.setStdModContent(Y.WidgetStdMod.HEADER,
'<h1 id="moodle-dialogue-' + this.get('COUNT') + '-header-text">' + this.get(TITLE) + '</h1>',
Y.WidgetStdMod.REPLACE);
this._closeEvents.push(
Y.on('key', this.submit, window, 'down:13', this),
yes.on('click', this.submit, this)
);
var closeButton = this.get('boundingBox').one('.closebutton');
if (closeButton) {
// The close button should act exactly like the 'No' button.
this._closeEvents.push(
closeButton.on('click', this.submit, this)
);
}
},
submit: function() {
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete');
this.hide();
this.destroy();
}
}, {
NAME: ALERT_NAME,
CSS_PREFIX: DIALOGUE_PREFIX,
ATTRS: {
/**
* The title of the alert.
*
* @attribute title
* @type String
* @default 'Alert'
*/
title: {
validator: Y.Lang.isString,
value: 'Alert'
},
/**
* The message of the alert.
*
* @attribute message
* @type String
* @default 'Confirm'
*/
message: {
validator: Y.Lang.isString,
value: 'Confirm'
},
/**
* The button text to use to accept the alert.
*
* @attribute yesLabel
* @type String
* @default 'Ok'
*/
yesLabel: {
validator: Y.Lang.isString,
setter: function(txt) {
if (!txt) {
txt = 'Ok';
}
return txt;
},
value: 'Ok'
}
}
});
M.core.alert = ALERT;