MDL-40678 JavaScript: Split out moodle-core-notification into submodules
[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,
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 alert to the user.
34 *
35 * @module moodle-core-notification
36 * @submodule moodle-core-notification-alert
37 */
38
39var ALERT_NAME = 'Moodle alert',
40 ALERT;
41
42/**
43 * Extends core Dialogue to show the alert dialogue.
44 *
45 * @param {Object} config Object literal specifying the dialogue configuration properties.
46 * @constructor
47 * @class M.core.alert
48 * @extends M.core.dialogue
49 */
50ALERT = function(config) {
51 config.closeButton = false;
52 ALERT.superclass.constructor.apply(this, [config]);
53};
54Y.extend(ALERT, M.core.dialogue, {
55 _enterKeypress : null,
56 initializer : function() {
57 this.publish('complete');
58 var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
59 content = Y.Node.create('<div class="confirmation-dialogue"></div>')
60 .append(Y.Node.create('<div class="confirmation-message">'+this.get('message')+'</div>'))
61 .append(Y.Node.create('<div class="confirmation-buttons"></div>')
62 .append(yes));
63 this.get(BASE).addClass('moodle-dialogue-confirm');
64 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
65 this.setStdModContent(Y.WidgetStdMod.HEADER,
66 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
67 this.after('destroyedChange', function(){this.get(BASE).remove();}, this);
68 this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this);
69 yes.on('click', this.submit, this);
70 },
71 submit : function() {
72 this._enterKeypress.detach();
73 this.fire('complete');
74 this.hide();
75 this.destroy();
76 }
77}, {
78 NAME : ALERT_NAME,
79 CSS_PREFIX : DIALOGUE_PREFIX,
80 ATTRS : {
81
82 /**
83 * The title of the alert.
84 *
85 * @attribute title
86 * @type String
87 * @default 'Alert'
88 */
89 title : {
90 validator : Y.Lang.isString,
91 value : 'Alert'
92 },
93
94 /**
95 * The message of the alert.
96 *
97 * @attribute message
98 * @type String
99 * @default 'Confirm'
100 */
101 message : {
102 validator : Y.Lang.isString,
103 value : 'Confirm'
104 },
105
106 /**
107 * The button text to use to accept the alert.
108 *
109 * @attribute yesLabel
110 * @type String
111 * @default 'Ok'
112 */
113 yesLabel : {
114 validator : Y.Lang.isString,
115 setter : function(txt) {
116 if (!txt) {
117 txt = 'Ok';
118 }
119 return txt;
120 },
121 value : 'Ok'
122 }
123 }
124});
125
126M.core.alert = ALERT;
127
128
129}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});