mod/bigbluebuttonbn/amd/src/actions.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. * JS actions.
  17. *
  18. * @module mod_bigbluebuttonbn/actions
  19. * @copyright 2021 Blindside Networks Inc
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import {endMeeting as requestEndMeeting} from './repository';
  23. import {
  24. exception as displayException,
  25. saveCancel,
  26. } from 'core/notification';
  27. import {notifySessionEnded} from './events';
  28. import {getString} from 'core/str';
  29. const confirmedPromise = (title, question, saveLabel) => new Promise(resolve => {
  30. saveCancel(title, question, saveLabel, resolve);
  31. });
  32. const registerEventListeners = () => {
  33. document.addEventListener('click', e => {
  34. const actionButton = e.target.closest('.bbb-btn-action[data-action="end"]');
  35. if (!actionButton) {
  36. return;
  37. }
  38. e.preventDefault();
  39. const bbbId = actionButton.dataset.bbbId;
  40. const groupId = actionButton.dataset.groupId ? actionButton.dataset.groupId : 0;
  41. confirmedPromise(
  42. getString('end_session_confirm_title', 'mod_bigbluebuttonbn'),
  43. getString('end_session_confirm', 'mod_bigbluebuttonbn'),
  44. getString('yes', 'moodle')
  45. )
  46. .then(() => requestEndMeeting(bbbId, groupId))
  47. .then(() => {
  48. notifySessionEnded(bbbId, groupId);
  49. return;
  50. })
  51. .catch(displayException);
  52. });
  53. };
  54. let listening = false;
  55. if (!listening) {
  56. registerEventListeners();
  57. listening = true;
  58. }