question/bank/editquestion/amd/src/question_status.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. * Status column selector js.
  17. *
  18. * @module qbank_editquestion/question_status
  19. * @copyright 2021 Catalyst IT Australia Pty Ltd
  20. * @author Safat Shahin <safatshahin@catalyst-au.net>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. import Ajax from 'core/ajax';
  24. import Notification from 'core/notification';
  25. /**
  26. * Set the question status.
  27. *
  28. * @param {Number} questionId The question id.
  29. * @param {String} status The updated question status.
  30. * @return {Array} The modified question status
  31. */
  32. const setQuestionStatus = (questionId, status) => Ajax.call([{
  33. methodname: 'qbank_editquestion_set_status',
  34. args: {
  35. questionid: questionId,
  36. status: status
  37. }
  38. }])[0];
  39. /**
  40. * Entrypoint of the js.
  41. *
  42. * @method init
  43. * @param {Number} questionId Question id.
  44. */
  45. export const init = (questionId) => {
  46. let target = document.querySelector('#question_status_dropdown-' + questionId);
  47. target.addEventListener('change', (e) => {
  48. const questionStatus = e.target.value;
  49. setQuestionStatus(questionId, questionStatus)
  50. .then((response) => {
  51. if (response.error) {
  52. Notification.addNotification({
  53. type: 'error',
  54. message: response.error
  55. });
  56. }
  57. return;
  58. }).catch();
  59. });
  60. };