admin/tool/lp/amd/src/competency_outcomes.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. * Competency rule config.
  17. *
  18. * @module tool_lp/competency_outcomes
  19. * @copyright 2015 Frédéric Massart - FMCorz.net
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. define(['jquery',
  23. 'core/str'],
  24. function($, Str) {
  25. var OUTCOME_NONE = 0,
  26. OUTCOME_EVIDENCE = 1,
  27. OUTCOME_COMPLETE = 2,
  28. OUTCOME_RECOMMEND = 3;
  29. return {
  30. NONE: OUTCOME_NONE,
  31. EVIDENCE: OUTCOME_EVIDENCE,
  32. COMPLETE: OUTCOME_COMPLETE,
  33. RECOMMEND: OUTCOME_RECOMMEND,
  34. /**
  35. * Get all the outcomes.
  36. *
  37. * @return {Object} Indexed by outcome code, contains code and name.
  38. * @method getAll
  39. */
  40. getAll: function() {
  41. var self = this;
  42. return Str.get_strings([
  43. {key: 'competencyoutcome_none', component: 'tool_lp'},
  44. {key: 'competencyoutcome_evidence', component: 'tool_lp'},
  45. {key: 'competencyoutcome_recommend', component: 'tool_lp'},
  46. {key: 'competencyoutcome_complete', component: 'tool_lp'},
  47. ]).then(function(strings) {
  48. var outcomes = {};
  49. outcomes[self.NONE] = {code: self.NONE, name: strings[0]};
  50. outcomes[self.EVIDENCE] = {code: self.EVIDENCE, name: strings[1]};
  51. outcomes[self.RECOMMEND] = {code: self.RECOMMEND, name: strings[2]};
  52. outcomes[self.COMPLETE] = {code: self.COMPLETE, name: strings[3]};
  53. return outcomes;
  54. });
  55. },
  56. /**
  57. * Get the string for an outcome.
  58. *
  59. * @param {Number} id The outcome code.
  60. * @return {Promise} Resolved with the string.
  61. * @method getString
  62. */
  63. getString: function(id) {
  64. var self = this,
  65. all = self.getAll();
  66. return all.then(function(outcomes) {
  67. if (typeof outcomes[id] === 'undefined') {
  68. return $.Deferred().reject().promise();
  69. }
  70. return outcomes[id].name;
  71. });
  72. }
  73. };
  74. });