admin/tool/lp/amd/src/competency_plan_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. * Event click on selecting competency in the competency autocomplete.
  17. *
  18. * @module tool_lp/competency_plan_navigation
  19. * @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. define(['jquery'], function($) {
  23. /**
  24. * CompetencyPlanNavigation
  25. *
  26. * @class
  27. * @param {String} competencySelector The selector of the competency element.
  28. * @param {String} baseUrl The base url for the page (no params).
  29. * @param {Number} userId The user id
  30. * @param {Number} competencyId The competency id
  31. * @param {Number} planId The plan id
  32. */
  33. var CompetencyPlanNavigation = function(competencySelector, baseUrl, userId, competencyId, planId) {
  34. this._baseUrl = baseUrl;
  35. this._userId = userId + '';
  36. this._competencyId = competencyId + '';
  37. this._planId = planId;
  38. this._ignoreFirstCompetency = true;
  39. $(competencySelector).on('change', this._competencyChanged.bind(this));
  40. };
  41. /**
  42. * The competency was changed in the select list.
  43. *
  44. * @method _competencyChanged
  45. * @param {Event} e
  46. */
  47. CompetencyPlanNavigation.prototype._competencyChanged = function(e) {
  48. if (this._ignoreFirstCompetency) {
  49. this._ignoreFirstCompetency = false;
  50. return;
  51. }
  52. var newCompetencyId = $(e.target).val();
  53. var queryStr = '?userid=' + this._userId + '&planid=' + this._planId + '&competencyid=' + newCompetencyId;
  54. document.location = this._baseUrl + queryStr;
  55. };
  56. /** @property {Number} The id of the competency. */
  57. CompetencyPlanNavigation.prototype._competencyId = null;
  58. /** @property {Number} The id of the user. */
  59. CompetencyPlanNavigation.prototype._userId = null;
  60. /** @property {Number} The id of the plan. */
  61. CompetencyPlanNavigation.prototype._planId = null;
  62. /** @property {String} Plugin base url. */
  63. CompetencyPlanNavigation.prototype._baseUrl = null;
  64. /** @property {Boolean} Ignore the first change event for competencies. */
  65. CompetencyPlanNavigation.prototype._ignoreFirstCompetency = null;
  66. return CompetencyPlanNavigation;
  67. });