Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
8
var 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
 */
19
CONFIRM = function(config) {
20
    CONFIRM.superclass.constructor.apply(this, [config]);
21
};
22
Y.extend(CONFIRM, M.core.notification.info, {
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
 
32
    /**
33
     * A reference to the yes button.
34
     *
35
     * @property _yesButton
36
     * @type Node
37
     * @private
38
     */
39
    _yesButton: null,
40
 
41
    /**
42
     * A reference to the No button.
43
     *
44
     * @property _noButton
45
     * @type Node
46
     * @private
47
     */
48
    _noButton: null,
49
 
50
    /**
51
     * A reference to the Question.
52
     *
53
     * @property _question
54
     * @type Node
55
     * @private
56
     */
57
    _question: null,
58
 
59
    initializer: function() {
60
        window.console.error(
61
            'The module "moodle-core-notification-confirm" module has been deprecated and will be removed in Moodle 4.4.'
62
        );
63
        this._closeEvents = [];
64
        this.publish('complete');
65
        this.publish('complete-yes');
66
        this.publish('complete-no');
67
        this._yesButton = Y.Node.create('<input type="button" class="btn btn-primary" id="id_yuiconfirmyes-' +
68
                                        this.get('COUNT') + '" value="' + this.get(CONFIRMYES) + '" />');
69
        this._noButton = Y.Node.create('<input type="button" class="btn btn-secondary" id="id_yuiconfirmno-' +
70
                                        this.get('COUNT') + '" value="' + this.get(CONFIRMNO) + '" />');
71
        this._question = Y.Node.create('<div class="confirmation-message">' + this.get(QUESTION) + '</div>');
72
        var content = Y.Node.create('<div class="confirmation-dialogue"></div>')
73
                        .append(this._question)
74
                        .append(Y.Node.create(
75
                            '<div class="confirmation-buttons d-flex flex-wrap align-items-center justify-content-around"></div>'
76
                        )
77
                        .append(this._yesButton)
78
                        .append(this._noButton));
79
        this.get(BASE).addClass('moodle-dialogue-confirm');
80
        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
81
        this.setStdModContent(Y.WidgetStdMod.HEADER,
82
                '<h5 id="moodle-dialogue-' + this.get('COUNT') + '-wrap-header-text">' + this.get(TITLE) + '</h5>',
83
                Y.WidgetStdMod.REPLACE);
84
 
85
        this._closeEvents.push(
86
            Y.on('key', this.submit, window, 'down:27', this, false),
87
            this._yesButton.on('click', this.submit, this, true),
88
            this._noButton.on('click', this.submit, this, false)
89
        );
90
 
91
        var closeButton = this.get('boundingBox').one('.closebutton');
92
        if (closeButton) {
93
            // The close button should act exactly like the 'No' button.
94
            this._closeEvents.push(
95
                closeButton.on('click', this.submit, this)
96
            );
97
        }
98
    },
99
    submit: function(e, outcome) {
100
        new Y.EventHandle(this._closeEvents).detach();
101
        this.fire('complete', outcome);
102
        if (outcome) {
103
            this.fire('complete-yes');
104
        } else {
105
            this.fire('complete-no');
106
        }
107
        this.hide();
108
        this.destroy();
109
    }
110
}, {
111
    NAME: CONFIRM_NAME,
112
    CSS_PREFIX: DIALOGUE_PREFIX,
113
    ATTRS: {
114
 
115
        /**
116
         * The button text to use to accept the confirmation.
117
         *
118
         * @attribute yesLabel
119
         * @type String
120
         * @default 'Yes'
121
         */
122
        yesLabel: {
123
            validator: Y.Lang.isString,
124
            valueFn: function() {
125
                return M.util.get_string('yes', 'moodle');
126
            },
127
            setter: function(value) {
128
                if (this._yesButton) {
129
                    this._yesButton.set('value', value);
130
                }
131
                return value;
132
            }
133
        },
134
 
135
        /**
136
         * The button text to use to reject the confirmation.
137
         *
138
         * @attribute noLabel
139
         * @type String
140
         * @default 'No'
141
         */
142
        noLabel: {
143
            validator: Y.Lang.isString,
144
            valueFn: function() {
145
                return M.util.get_string('no', 'moodle');
146
            },
147
            setter: function(value) {
148
                if (this._noButton) {
149
                    this._noButton.set('value', value);
150
                }
151
                return value;
152
            }
153
        },
154
 
155
        /**
156
         * The title of the dialogue.
157
         *
158
         * @attribute title
159
         * @type String
160
         * @default 'Confirm'
161
         */
162
        title: {
163
            validator: Y.Lang.isString,
164
            value: M.util.get_string('confirm', 'moodle')
165
        },
166
 
167
        /**
168
         * The question posed by the dialogue.
169
         *
170
         * @attribute question
171
         * @type String
172
         * @default 'Are you sure?'
173
         */
174
        question: {
175
            validator: Y.Lang.isString,
176
            valueFn: function() {
177
                return M.util.get_string('areyousure', 'moodle');
178
            },
179
            setter: function(value) {
180
                if (this._question) {
181
                    this._question.set('value', value);
182
                }
183
                return value;
184
            }
185
        }
186
    }
187
});
188
Y.augment(CONFIRM, Y.EventTarget);
189
 
190
M.core.confirm = CONFIRM;