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 navigation between users in a course.
18
 *
19
 * @module report_competency/user_course_navigation
20
 * @copyright  2015 Damyon Wiese
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
define(['jquery'], function($) {
25
 
26
    /**
27
     * UserCourseNavigation
28
     *
29
     * @class report_competency/user_course_navigation
30
     * @param {String} userSelector The selector of the user element.
31
     * @param {String} moduleSelector The selector of the module element.
32
     * @param {String} baseUrl The base url for the page (no params).
33
     * @param {Number} userId The course id
34
     * @param {Number} courseId The user id
35
     * @param {Number} moduleId The activity module (filter)
36
     */
37
    var UserCourseNavigation = function(userSelector, moduleSelector, baseUrl, userId, courseId, moduleId) {
38
        this._baseUrl = baseUrl;
39
        this._userId = userId + '';
40
        this._courseId = courseId;
41
        this._moduleId = moduleId;
42
 
43
        $(userSelector).on('change', this._userChanged.bind(this));
44
        $(moduleSelector).on('change', this._moduleChanged.bind(this));
45
    };
46
 
47
    /**
48
     * The user was changed in the select list.
49
     *
50
     * @method _userChanged
51
     * @param {Event} e the event
52
     */
53
    UserCourseNavigation.prototype._userChanged = function(e) {
54
        // Note: This change causes a page reload and is intentionally not paired with a js_complete call.
55
        M.util.js_pending('report_competency/user_course_navigation:_userChanged');
56
        var newUserId = $(e.target).val();
57
        var queryStr = '?user=' + newUserId + '&id=' + this._courseId + '&mod=' + this._moduleId;
58
        document.location = this._baseUrl + queryStr;
59
    };
60
 
61
    /**
62
     * The module was changed in the select list.
63
     *
64
     * @method _moduleChanged
65
     * @param {Event} e the event
66
     */
67
    UserCourseNavigation.prototype._moduleChanged = function(e) {
68
        // Note: This change causes a page reload and is intentionally not paired with a js_complete call.
69
        M.util.js_pending('report_competency/user_course_navigation:_moduleChanged');
70
        var newModuleId = $(e.target).val();
71
        var queryStr = '?mod=' + newModuleId + '&id=' + this._courseId + '&user=' + this._userId;
72
        document.location = this._baseUrl + queryStr;
73
    };
74
 
75
    /** @property {Number} The id of the user. */
76
    UserCourseNavigation.prototype._userId = null;
77
    /** @property {Number} The id of the module. */
78
    UserCourseNavigation.prototype._moduleId = null;
79
    /** @property {Number} The id of the course. */
80
    UserCourseNavigation.prototype._courseId = null;
81
    /** @property {String} Plugin base url. */
82
    UserCourseNavigation.prototype._baseUrl = null;
83
 
84
    return UserCourseNavigation;
85
});