~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
YUI.add('moodle-core-notification-alert', function (Y, NAME) {
 
2
 
 
3
var DIALOGUE_PREFIX,
 
4
    BASE,
 
5
    CONFIRMYES,
 
6
    CONFIRMNO,
 
7
    TITLE,
 
8
    QUESTION,
 
9
    CSS;
 
10
 
 
11
DIALOGUE_PREFIX = 'moodle-dialogue',
 
12
BASE = 'notificationBase',
 
13
CONFIRMYES = 'yesLabel',
 
14
CONFIRMNO = 'noLabel',
 
15
TITLE = 'title',
 
16
QUESTION = 'question',
 
17
CSS = {
 
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.
 
29
M.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
 
 
37
var 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
 */
 
48
ALERT = function(config) {
 
49
    config.closeButton = false;
 
50
    ALERT.superclass.constructor.apply(this, [config]);
 
51
};
 
52
Y.extend(ALERT, M.core.dialogue, {
 
53
    /**
 
54
     * The list of events to detach when destroying this dialogue.
 
55
     *
 
56
     * @property _closeEvents
 
57
     * @type EventHandle[]
 
58
     * @private
 
59
     */
 
60
    _closeEvents: null,
 
61
    initializer : function() {
 
62
        this._closeEvents = [];
 
63
        this.publish('complete');
 
64
        var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
 
65
            content = Y.Node.create('<div class="confirmation-dialogue"></div>')
 
66
                    .append(Y.Node.create('<div class="confirmation-message">'+this.get('message')+'</div>'))
 
67
                    .append(Y.Node.create('<div class="confirmation-buttons"></div>')
 
68
                            .append(yes));
 
69
        this.get(BASE).addClass('moodle-dialogue-confirm');
 
70
        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
 
71
        this.setStdModContent(Y.WidgetStdMod.HEADER,
 
72
                '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
 
73
        this.after('destroyedChange', function(){this.get(BASE).remove();}, this);
 
74
        this._closeEvents.push(
 
75
            Y.on('key', this.submit, window, 'down:13', this),
 
76
            yes.on('click', this.submit, this)
 
77
        );
 
78
 
 
79
        var closeButton = this.get('boundingBox').one('.closebutton');
 
80
        if (closeButton) {
 
81
            // The close button should act exactly like the 'No' button.
 
82
            this._closeEvents.push(
 
83
                closeButton.on('click', this.submit, this)
 
84
            );
 
85
        }
 
86
    },
 
87
    submit : function() {
 
88
        new Y.EventHandle(this._closeEvents).detach();
 
89
        this.fire('complete');
 
90
        this.hide();
 
91
        this.destroy();
 
92
    }
 
93
}, {
 
94
    NAME : ALERT_NAME,
 
95
    CSS_PREFIX : DIALOGUE_PREFIX,
 
96
    ATTRS : {
 
97
 
 
98
        /**
 
99
         * The title of the alert.
 
100
         *
 
101
         * @attribute title
 
102
         * @type String
 
103
         * @default 'Alert'
 
104
         */
 
105
        title : {
 
106
            validator : Y.Lang.isString,
 
107
            value : 'Alert'
 
108
        },
 
109
 
 
110
        /**
 
111
         * The message of the alert.
 
112
         *
 
113
         * @attribute message
 
114
         * @type String
 
115
         * @default 'Confirm'
 
116
         */
 
117
        message : {
 
118
            validator : Y.Lang.isString,
 
119
            value : 'Confirm'
 
120
        },
 
121
 
 
122
        /**
 
123
         * The button text to use to accept the alert.
 
124
         *
 
125
         * @attribute yesLabel
 
126
         * @type String
 
127
         * @default 'Ok'
 
128
         */
 
129
        yesLabel : {
 
130
            validator : Y.Lang.isString,
 
131
            setter : function(txt) {
 
132
                if (!txt) {
 
133
                    txt = 'Ok';
 
134
                }
 
135
                return txt;
 
136
            },
 
137
            value : 'Ok'
 
138
        }
 
139
    }
 
140
});
 
141
 
 
142
M.core.alert = ALERT;
 
143
 
 
144
 
 
145
}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});