Revert "Merge branch 'm28_MDL-46431' of https://github.com/totara/moodle"
[moodle.git] / lib / yui / src / notification / js / confirm.js
CommitLineData
78686995
AN
1/**
2 * A dialogue type designed to display a confirmation to the user.
3 *
4 * @module moodle-core-notification
5 * @submodule moodle-core-notification-confirm
6 */
7
8var CONFIRM_NAME = 'Moodle confirmation dialogue',
9 CONFIRM;
10
11/**
12 * Extends core Dialogue to show the confirmation dialogue.
13 *
14 * @param {Object} config Object literal specifying the dialogue configuration properties.
15 * @constructor
16 * @class M.core.confirm
17 * @extends M.core.dialogue
18 */
19CONFIRM = function(config) {
20 CONFIRM.superclass.constructor.apply(this, [config]);
21};
cfa770b4 22Y.extend(CONFIRM, M.core.notification.info, {
f857b668
AN
23 /**
24 * The list of events to detach when destroying this dialogue.
25 *
26 * @property _closeEvents
27 * @type EventHandle[]
28 * @private
29 */
30 _closeEvents: null,
31 initializer: function() {
32 this._closeEvents = [];
78686995
AN
33 this.publish('complete');
34 this.publish('complete-yes');
35 this.publish('complete-no');
36 var yes = Y.Node.create('<input type="button" id="id_yuiconfirmyes-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
37 no = Y.Node.create('<input type="button" id="id_yuiconfirmno-' + this.get('COUNT') + '" value="'+this.get(CONFIRMNO)+'" />'),
38 content = Y.Node.create('<div class="confirmation-dialogue"></div>')
39 .append(Y.Node.create('<div class="confirmation-message">'+this.get(QUESTION)+'</div>'))
40 .append(Y.Node.create('<div class="confirmation-buttons"></div>')
41 .append(yes)
42 .append(no));
43 this.get(BASE).addClass('moodle-dialogue-confirm');
44 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
45 this.setStdModContent(Y.WidgetStdMod.HEADER,
c44012e0 46 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
649c80e6 47
f857b668 48 this._closeEvents.push(
649c80e6
AN
49 Y.on('key', this.submit, window, 'down:27', this, false),
50 yes.on('click', this.submit, this, true),
51 no.on('click', this.submit, this, false)
52 );
53
54 var closeButton = this.get('boundingBox').one('.closebutton');
55 if (closeButton) {
56 // The close button should act exactly like the 'No' button.
f857b668 57 this._closeEvents.push(
649c80e6
AN
58 closeButton.on('click', this.submit, this)
59 );
60 }
78686995 61 },
f857b668
AN
62 submit: function(e, outcome) {
63 new Y.EventHandle(this._closeEvents).detach();
78686995
AN
64 this.fire('complete', outcome);
65 if (outcome) {
66 this.fire('complete-yes');
67 } else {
68 this.fire('complete-no');
69 }
70 this.hide();
71 this.destroy();
72 }
73}, {
f857b668
AN
74 NAME: CONFIRM_NAME,
75 CSS_PREFIX: DIALOGUE_PREFIX,
76 ATTRS: {
78686995
AN
77
78 /**
79 * The button text to use to accept the confirmation.
80 *
81 * @attribute yesLabel
82 * @type String
83 * @default 'Yes'
84 */
f857b668
AN
85 yesLabel: {
86 validator: Y.Lang.isString,
0d1d5423 87 value: M.util.get_string('yes', 'moodle')
78686995
AN
88 },
89
90 /**
91 * The button text to use to reject the confirmation.
92 *
93 * @attribute noLabel
94 * @type String
95 * @default 'No'
96 */
f857b668
AN
97 noLabel: {
98 validator: Y.Lang.isString,
0d1d5423 99 value: M.util.get_string('no', 'moodle')
78686995
AN
100 },
101
102 /**
103 * The title of the dialogue.
104 *
105 * @attribute title
106 * @type String
107 * @default 'Confirm'
108 */
f857b668
AN
109 title: {
110 validator: Y.Lang.isString,
0d1d5423 111 value: M.util.get_string('confirm', 'moodle')
78686995
AN
112 },
113
114 /**
115 * The question posed by the dialogue.
116 *
117 * @attribute question
118 * @type String
119 * @default 'Are you sure?'
120 */
f857b668
AN
121 question: {
122 validator: Y.Lang.isString,
0d1d5423 123 value: M.util.get_string('areyousure', 'moodle')
78686995
AN
124 }
125 }
126});
127Y.augment(CONFIRM, Y.EventTarget);
128
129M.core.confirm = CONFIRM;