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     tool_lp/dialogue
21
 * @copyright  2015 Damyon Wiese <damyon@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
    // Private variables and functions.
27
    /**
28
     * Constructor
29
     *
30
     * @param {String} title Title for the window.
31
     * @param {String} content The content for the window.
32
     * @param {function} afterShow Callback executed after the window is opened.
33
     * @param {function} afterHide Callback executed after the window is closed.
34
     * @param {Boolean} wide Specify we want an extra wide dialogue (the size is standard, but wider than the default).
35
     * @param {String} height The height of the dialogue.
36
     */
37
    var dialogue = function(title, content, afterShow, afterHide, wide, height) {
38
        M.util.js_pending('tool_lp/dialogue:dialogue');
39
 
40
        this.yuiDialogue = null;
41
        var parent = this;
42
 
43
        // Default for wide is false.
44
        if (typeof wide == 'undefined') {
45
            wide = false;
46
        }
47
 
48
        Y.use('moodle-core-notification', 'timers', function() {
49
            var width = '480px';
50
            if (wide) {
51
                width = '800px';
52
            }
53
 
54
            if (!height) {
55
                height = 'auto';
56
            }
57
 
58
            parent.yuiDialogue = new M.core.dialogue({
59
                headerContent: title,
60
                bodyContent: content,
61
                draggable: true,
62
                visible: false,
63
                center: true,
64
                modal: true,
65
                width: width,
66
                height: height
67
            });
68
 
69
            parent.yuiDialogue.before('visibleChange', function() {
70
                M.util.js_pending('tool_lp/dialogue:before:visibleChange');
71
            });
72
 
73
            parent.yuiDialogue.after('visibleChange', function(e) {
74
                if (e.newVal) {
75
                    // Delay the callback call to the next tick, otherwise it can happen that it is
76
                    // executed before the dialogue constructor returns.
77
                    if ((typeof afterShow !== 'undefined')) {
78
                        Y.soon(function() {
79
                            afterShow(parent);
80
                            parent.yuiDialogue.centerDialogue();
81
                            M.util.js_complete('tool_lp/dialogue:before:visibleChange');
82
                        });
83
                    } else {
84
                        M.util.js_complete('tool_lp/dialogue:before:visibleChange');
85
                    }
86
                } else {
87
                    if ((typeof afterHide !== 'undefined')) {
88
                        Y.soon(function() {
89
                            afterHide(parent);
90
                            M.util.js_complete('tool_lp/dialogue:before:visibleChange');
91
                        });
92
                    } else {
93
                        M.util.js_complete('tool_lp/dialogue:before:visibleChange');
94
                    }
95
                }
96
            });
97
 
98
            parent.yuiDialogue.show();
99
            M.util.js_complete('tool_lp/dialogue:dialogue');
100
        });
101
    };
102
 
103
    /**
104
     * Close this window.
105
     */
106
    dialogue.prototype.close = function() {
107
        this.yuiDialogue.hide();
108
        this.yuiDialogue.destroy();
109
    };
110
 
111
    /**
112
     * Get content.
113
     * @return {node}
114
     */
115
    dialogue.prototype.getContent = function() {
116
        return this.yuiDialogue.bodyNode.getDOMNode();
117
    };
118
 
119
    return /** @alias module:tool_lp/dialogue */ dialogue;
120
});