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
 * Module to refresh a user competency summary in a page.
18
 *
19
 * @module     tool_lp/user_competency_info
20
 * @copyright  2015 Damyon Wiese
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
define(['jquery', 'core/notification', 'core/ajax', 'core/templates'], function($, notification, ajax, templates) {
25
 
26
    /**
27
     * Info
28
     *
29
     * @param {JQuery} rootElement Selector to replace when the information needs updating.
30
     * @param {Number} competencyId The id of the competency.
31
     * @param {Number} userId The id of the user.
32
     * @param {Number} planId The id of the plan.
33
     * @param {Number} courseId The id of the course.
34
     * @param {Boolean} displayuser If we should display the user info.
35
     */
36
    var Info = function(rootElement, competencyId, userId, planId, courseId, displayuser) {
37
        this._rootElement = rootElement;
38
        this._competencyId = competencyId;
39
        this._userId = userId;
40
        this._planId = planId;
41
        this._courseId = courseId;
42
        this._valid = true;
43
        this._displayuser = (typeof displayuser !== 'undefined') ? displayuser : false;
44
 
45
        if (this._planId) {
46
            this._methodName = 'tool_lp_data_for_user_competency_summary_in_plan';
47
            this._args = {competencyid: this._competencyId, planid: this._planId};
48
            this._templateName = 'tool_lp/user_competency_summary_in_plan';
49
        } else if (this._courseId) {
50
            this._methodName = 'tool_lp_data_for_user_competency_summary_in_course';
51
            this._args = {userid: this._userId, competencyid: this._competencyId, courseid: this._courseId};
52
            this._templateName = 'tool_lp/user_competency_summary_in_course';
53
        } else {
54
            this._methodName = 'tool_lp_data_for_user_competency_summary';
55
            this._args = {userid: this._userId, competencyid: this._competencyId};
56
            this._templateName = 'tool_lp/user_competency_summary';
57
        }
58
    };
59
 
60
    /**
61
     * Reload the info for this user competency.
62
     *
63
     * @method reload
64
     */
65
    Info.prototype.reload = function() {
66
        var self = this,
67
            promises = [];
68
 
69
        if (!this._valid) {
70
            return;
71
        }
72
 
73
        promises = ajax.call([{
74
            methodname: this._methodName,
75
            args: this._args
76
        }]);
77
 
78
        promises[0].done(function(context) {
79
            // Check if we should also the user info.
80
            if (self._displayuser) {
81
                context.displayuser = true;
82
            }
83
            templates.render(self._templateName, context).done(function(html, js) {
84
                templates.replaceNode(self._rootElement, html, js);
85
            }).fail(notification.exception);
86
        }).fail(notification.exception);
87
    };
88
 
89
    /** @property {JQuery} The root element to replace in the DOM. */
90
    Info.prototype._rootElement = null;
91
    /** @property {Number} The id of the course. */
92
    Info.prototype._courseId = null;
93
    /** @property {Boolean} Is this module valid? */
94
    Info.prototype._valid = null;
95
    /** @property {Number} The id of the plan. */
96
    Info.prototype._planId = null;
97
    /** @property {Number} The id of the competency. */
98
    Info.prototype._competencyId = null;
99
    /** @property {Number} The id of the user. */
100
    Info.prototype._userId = null;
101
    /** @property {String} The method name to load the data. */
102
    Info.prototype._methodName = null;
103
    /** @property {Object} The arguments to load the data. */
104
    Info.prototype._args = null;
105
    /** @property {String} The template to reload the fragment. */
106
    Info.prototype._templateName = null;
107
    /** @property {Boolean} If we should display the user info? */
108
    Info.prototype._displayuser = false;
109
 
110
    return /** @alias module:tool_lp/user_competency_info */ Info;
111
 
112
});