Merge branch 'MDL-40716-master' of https://github.com/andrewnicols/moodle
[moodle.git] / lib / yui / build / moodle-core-notification-alert / moodle-core-notification-alert.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, {
649c80e6 53 closeEvents: [],
78686995
AN
54 initializer : function() {
55 this.publish('complete');
56 var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
57 content = Y.Node.create('<div class="confirmation-dialogue"></div>')
58 .append(Y.Node.create('<div class="confirmation-message">'+this.get('message')+'</div>'))
59 .append(Y.Node.create('<div class="confirmation-buttons"></div>')
60 .append(yes));
61 this.get(BASE).addClass('moodle-dialogue-confirm');
62 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
63 this.setStdModContent(Y.WidgetStdMod.HEADER,
64 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
2f166b32 65
649c80e6
AN
66 this.closeEvents.push(
67 Y.on('key', this.submit, window, 'down:13', this),
68 yes.on('click', this.submit, this)
69 );
70
71 var closeButton = this.get('boundingBox').one('.closebutton');
72 if (closeButton) {
73 // The close button should act exactly like the 'No' button.
74 this.closeEvents.push(
75 closeButton.on('click', this.submit, this)
76 );
77 }
78686995
AN
78 },
79 submit : function() {
649c80e6 80 new Y.EventHandle(this.closeEvents).detach();
78686995
AN
81 this.fire('complete');
82 this.hide();
83 this.destroy();
84 }
85}, {
86 NAME : ALERT_NAME,
87 CSS_PREFIX : DIALOGUE_PREFIX,
88 ATTRS : {
89
90 /**
91 * The title of the alert.
92 *
93 * @attribute title
94 * @type String
95 * @default 'Alert'
96 */
97 title : {
98 validator : Y.Lang.isString,
99 value : 'Alert'
100 },
101
102 /**
103 * The message of the alert.
104 *
105 * @attribute message
106 * @type String
107 * @default 'Confirm'
108 */
109 message : {
110 validator : Y.Lang.isString,
111 value : 'Confirm'
112 },
113
114 /**
115 * The button text to use to accept the alert.
116 *
117 * @attribute yesLabel
118 * @type String
119 * @default 'Ok'
120 */
121 yesLabel : {
122 validator : Y.Lang.isString,
123 setter : function(txt) {
124 if (!txt) {
125 txt = 'Ok';
126 }
127 return txt;
128 },
129 value : 'Ok'
130 }
131 }
132});
133
134M.core.alert = ALERT;
135
136
137}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});