Revert "Merge branch 'm28_MDL-46431' of https://github.com/totara/moodle"
[moodle.git] / lib / yui / build / moodle-core-notification-alert / moodle-core-notification-alert-debug.js
CommitLineData
78686995
AN
1YUI.add('moodle-core-notification-alert', 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 alert to the user.
32 *
33 * @module moodle-core-notification
34 * @submodule moodle-core-notification-alert
35 */
36
37var ALERT_NAME = 'Moodle alert',
38 ALERT;
39
40/**
41 * Extends core Dialogue to show the alert dialogue.
42 *
43 * @param {Object} config Object literal specifying the dialogue configuration properties.
44 * @constructor
45 * @class M.core.alert
46 * @extends M.core.dialogue
47 */
48ALERT = function(config) {
49 config.closeButton = false;
50 ALERT.superclass.constructor.apply(this, [config]);
51};
cfa770b4 52Y.extend(ALERT, M.core.notification.info, {
f857b668
AN
53 /**
54 * The list of events to detach when destroying this dialogue.
55 *
56 * @property _closeEvents
57 * @type EventHandle[]
58 * @private
59 */
60 _closeEvents: null,
61 initializer: function() {
62 this._closeEvents = [];
78686995
AN
63 this.publish('complete');
64 var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
65 content = Y.Node.create('<div class="confirmation-dialogue"></div>')
66 .append(Y.Node.create('<div class="confirmation-message">'+this.get('message')+'</div>'))
67 .append(Y.Node.create('<div class="confirmation-buttons"></div>')
68 .append(yes));
69 this.get(BASE).addClass('moodle-dialogue-confirm');
70 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
71 this.setStdModContent(Y.WidgetStdMod.HEADER,
c44012e0 72 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
2f166b32 73
f857b668 74 this._closeEvents.push(
649c80e6
AN
75 Y.on('key', this.submit, window, 'down:13', this),
76 yes.on('click', this.submit, this)
77 );
78
79 var closeButton = this.get('boundingBox').one('.closebutton');
80 if (closeButton) {
81 // The close button should act exactly like the 'No' button.
f857b668 82 this._closeEvents.push(
649c80e6
AN
83 closeButton.on('click', this.submit, this)
84 );
85 }
78686995 86 },
f857b668
AN
87 submit: function() {
88 new Y.EventHandle(this._closeEvents).detach();
78686995
AN
89 this.fire('complete');
90 this.hide();
91 this.destroy();
92 }
93}, {
f857b668
AN
94 NAME: ALERT_NAME,
95 CSS_PREFIX: DIALOGUE_PREFIX,
96 ATTRS: {
78686995
AN
97
98 /**
99 * The title of the alert.
100 *
101 * @attribute title
102 * @type String
103 * @default 'Alert'
104 */
f857b668
AN
105 title: {
106 validator: Y.Lang.isString,
107 value: 'Alert'
78686995
AN
108 },
109
110 /**
111 * The message of the alert.
112 *
113 * @attribute message
114 * @type String
115 * @default 'Confirm'
116 */
f857b668
AN
117 message: {
118 validator: Y.Lang.isString,
119 value: 'Confirm'
78686995
AN
120 },
121
122 /**
123 * The button text to use to accept the alert.
124 *
125 * @attribute yesLabel
126 * @type String
127 * @default 'Ok'
128 */
f857b668
AN
129 yesLabel: {
130 validator: Y.Lang.isString,
131 setter: function(txt) {
78686995
AN
132 if (!txt) {
133 txt = 'Ok';
134 }
135 return txt;
136 },
f857b668 137 value: 'Ok'
78686995
AN
138 }
139 }
140});
141
142M.core.alert = ALERT;
143
144
145}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});