Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Wrapper for the YUI M.core.notification class. Allows us to
18
 * use the YUI version in AMD code until it is replaced.
19
 *
20
 * @module     mod_customcert/dialogue
21
 * @copyright  2016 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
define(['core/yui'], function(Y) {
25
 
26
    /**
27
     * Constructor
28
     *
29
     * @param {String} title Title for the window.
30
     * @param {String} content The content for the window.
31
     * @param {function} afterShow Callback executed after the window is opened.
32
     * @param {function} afterHide Callback executed after the window is closed.
33
     * @param {Boolean} wide Specify we want an extra wide dialogue (the size is standard, but wider than the default).
34
     */
35
    var dialogue = function(title, content, afterShow, afterHide, wide) {
36
        this.yuiDialogue = null;
37
        var parent = this;
38
 
39
        // Default for wide is false.
40
        if (typeof wide == 'undefined') {
41
            wide = false;
42
        }
43
 
44
        Y.use('moodle-core-notification', 'timers', function() {
45
            var width = '480px';
46
            if (wide) {
47
                width = '800px';
48
            }
49
 
50
            parent.yuiDialogue = new M.core.dialogue({
51
                headerContent: title,
52
                bodyContent: content,
53
                draggable: true,
54
                visible: false,
55
                center: true,
56
                modal: true,
57
                width: width
58
            });
59
 
60
            parent.yuiDialogue.after('visibleChange', function(e) {
61
                if (e.newVal) {
62
                    // Delay the callback call to the next tick, otherwise it can happen that it is
63
                    // executed before the dialogue constructor returns.
64
                    if ((typeof afterShow !== 'undefined')) {
65
                        Y.soon(function() {
66
                            afterShow(parent);
67
                            parent.yuiDialogue.centerDialogue();
68
                        });
69
                    }
70
                } else {
71
                    if ((typeof afterHide !== 'undefined')) {
72
                        Y.soon(function() {
73
                            afterHide(parent);
74
                        });
75
                    }
76
                }
77
            });
78
 
79
            parent.yuiDialogue.show();
80
        });
81
    };
82
 
83
    /**
84
     * Close this window.
85
     */
86
    dialogue.prototype.close = function() {
87
        this.yuiDialogue.hide();
88
        this.yuiDialogue.destroy();
89
    };
90
 
91
    /**
92
     * Get content.
93
     *
94
     * @returns {HTMLElement}
95
     */
96
    dialogue.prototype.getContent = function() {
97
        return this.yuiDialogue.bodyNode.getDOMNode();
98
    };
99
 
100
    return dialogue;
101
});