report/competency/amd/src/user_course_navigation.js

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