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 an alert to the user.
3
 *
4
 * @module moodle-core-notification
5
 * @submodule moodle-core-notification-alert
6
 */
7
 
8
var ALERT_NAME = 'Moodle alert',
9
    ALERT;
10
 
11
/**
12
 * Extends core Dialogue to show the alert dialogue.
13
 *
14
 * @param {Object} config Object literal specifying the dialogue configuration properties.
15
 * @constructor
16
 * @class M.core.alert
17
 * @extends M.core.dialogue
18
 */
19
ALERT = function(config) {
20
    config.closeButton = false;
21
    ALERT.superclass.constructor.apply(this, [config]);
22
};
23
Y.extend(ALERT, M.core.notification.info, {
24
    /**
25
     * The list of events to detach when destroying this dialogue.
26
     *
27
     * @property _closeEvents
28
     * @type EventHandle[]
29
     * @private
30
     */
31
    _closeEvents: null,
32
    initializer: function() {
33
        this._closeEvents = [];
34
        this.publish('complete');
35
        var yes = Y.Node.create('<input type="button" class="btn btn-primary" id="id_yuialertconfirm-' + this.get('COUNT') + '"' +
36
                                 'value="' + this.get(CONFIRMYES) + '" />'),
37
            content = Y.Node.create('<div class="confirmation-dialogue"></div>')
38
                    .append(Y.Node.create('<div class="confirmation-message">' + this.get('message') + '</div>'))
39
                    .append(Y.Node.create('<div class="confirmation-buttons text-xs-right"></div>')
40
                            .append(yes));
41
        this.get(BASE).addClass('moodle-dialogue-confirm');
42
        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
43
        this.setStdModContent(Y.WidgetStdMod.HEADER,
44
                '<h5 id="moodle-dialogue-' + this.get('COUNT') + '-wrap-header-text">' + this.get(TITLE) + '</h5>',
45
                Y.WidgetStdMod.REPLACE);
46
 
47
        this._closeEvents.push(
48
            Y.on('key', this.submit, window, 'down:13', this),
49
            yes.on('click', this.submit, this)
50
        );
51
 
52
        var closeButton = this.get('boundingBox').one('.closebutton');
53
        if (closeButton) {
54
            // The close button should act exactly like the 'No' button.
55
            this._closeEvents.push(
56
                closeButton.on('click', this.submit, this)
57
            );
58
        }
59
    },
60
    submit: function() {
61
        new Y.EventHandle(this._closeEvents).detach();
62
        this.fire('complete');
63
        this.hide();
64
        this.destroy();
65
    }
66
}, {
67
    NAME: ALERT_NAME,
68
    CSS_PREFIX: DIALOGUE_PREFIX,
69
    ATTRS: {
70
 
71
        /**
72
         * The title of the alert.
73
         *
74
         * @attribute title
75
         * @type String
76
         * @default 'Alert'
77
         */
78
        title: {
79
            validator: Y.Lang.isString,
80
            value: 'Alert'
81
        },
82
 
83
        /**
84
         * The message of the alert.
85
         *
86
         * @attribute message
87
         * @type String
88
         * @default 'Confirm'
89
         */
90
        message: {
91
            validator: Y.Lang.isString,
92
            value: 'Confirm'
93
        },
94
 
95
        /**
96
         * The button text to use to accept the alert.
97
         *
98
         * @attribute yesLabel
99
         * @type String
100
         * @default 'OK'
101
         */
102
        yesLabel: {
103
            validator: Y.Lang.isString,
104
            setter: function(txt) {
105
                if (!txt) {
106
                    txt = 'OK';
107
                }
108
                return txt;
109
            },
110
            value: 'OK'
111
        }
112
    }
113
});
114
 
115
M.core.alert = ALERT;