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
 * Controls the contact page in the message drawer.
18
 *
19
 * @module     core_message/message_drawer_view_contact
20
 * @copyright  2018 Ryan Wyllie <ryan@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
define(
24
[
25
    'jquery',
26
    'core/str',
27
    'core/templates'
28
],
29
function(
30
    $,
31
    Str,
32
    Templates
33
) {
34
 
35
    var SELECTORS = {
36
        CONTENT_CONTAINER: '[data-region="content-container"]'
37
    };
38
 
39
    var TEMPLATES = {
40
        CONTENT: 'core_message/message_drawer_view_contact_body_content'
41
    };
42
 
43
    /**
44
     * Get the content container of the contact view container.
45
     *
46
     * @param {Object} root Contact container element.
47
     * @returns {Object} jQuery object
48
     */
49
    var getContentContainer = function(root) {
50
        return root.find(SELECTORS.CONTENT_CONTAINER);
51
    };
52
 
53
    /**
54
     * Render the contact profile in the content container.
55
     *
56
     * @param {Object} root Contact container element.
57
     * @param {Object} profile Contact profile details.
58
     * @returns {Object} jQuery promise
59
     */
60
    var render = function(root, profile) {
61
        return Templates.render(TEMPLATES.CONTENT, profile)
62
            .then(function(html) {
63
                getContentContainer(root).append(html);
64
                return html;
65
            });
66
    };
67
 
68
    /**
69
     * Setup the contact page.
70
     *
71
     * @param {string} namespace The route namespace.
72
     * @param {Object} header Contact header element.
73
     * @param {Object} body Contact body container element.
74
     * @param {Object} footer Contact footer container element.
75
     * @param {Object} contact The contact object.
76
     * @returns {Object} jQuery promise
77
     */
78
    var show = function(namespace, header, body, footer, contact) {
79
        var root = $(body);
80
 
81
        getContentContainer(root).empty();
82
        return render(root, contact);
83
    };
84
 
85
    /**
86
     * String describing this page used for aria-labels.
87
     *
88
     * @param {Object} root Contact container element.
89
     * @param {Object} contact The contact object.
90
     * @return {Object} jQuery promise
91
     */
92
    var description = function(root, contact) {
93
        return Str.get_string('messagedrawerviewcontact', 'core_message', contact.fullname);
94
    };
95
 
96
    return {
97
        show: show,
98
        description: description
99
    };
100
});