mod/assign/amd/src/bulkactions/grading/setmarkingallocation.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. * Bulk action for allocating markers in the assignment grading page.
  17. *
  18. * @module mod_assign/bulkactions/grading/setmarkingallocation
  19. * @copyright 2024 Shamim Rezaie <shamim@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import BulkAction from 'core/bulkactions/bulk_action';
  23. import Templates from 'core/templates';
  24. import {getString} from 'core/str';
  25. import SaveCancelModal from 'core/modal_save_cancel';
  26. import ModalEvents from 'core/modal_events';
  27. const Selectors = {
  28. selectBulkItemCheckbox: 'input[type="checkbox"][name="selectedusers"]:checked',
  29. };
  30. export default class extends BulkAction {
  31. /** @type {number} The course module ID. */
  32. #cmid;
  33. /** @type {string} The session key. */
  34. #sesskey;
  35. /**
  36. * The class constructor.
  37. *
  38. * @param {number} cmid The course module ID.
  39. * @param {string} sesskey The session key.
  40. */
  41. constructor(cmid, sesskey) {
  42. super();
  43. this.#cmid = cmid;
  44. this.#sesskey = sesskey;
  45. }
  46. getBulkActionTriggerSelector() {
  47. return '[data-type="bulkactions"] [data-action="setmarkingallocation"]';
  48. }
  49. async triggerBulkAction() {
  50. const selectedUsers = [...document.querySelectorAll(Selectors.selectBulkItemCheckbox)].map(checkbox => checkbox.value);
  51. const modal = await SaveCancelModal.create({
  52. title: await getString('setmarkingallocation', 'mod_assign'),
  53. buttons: {
  54. save: await getString('batchoperationsetmarkingallocation', 'mod_assign'),
  55. },
  56. body: Templates.render('mod_assign/bulkactions/grading/bulk_action_modal_body', {
  57. text: await getString('batchoperationconfirmsetmarkingallocation', 'mod_assign'),
  58. operation: 'setmarkingallocation',
  59. cmid: this.#cmid,
  60. selectedusers: selectedUsers.join(','),
  61. sesskey: this.#sesskey
  62. }),
  63. show: true,
  64. removeOnClose: true,
  65. });
  66. // Handle save event.
  67. modal.getRoot().on(ModalEvents.save, (e) => {
  68. e.preventDefault();
  69. modal.getRoot().find('form').submit();
  70. });
  71. }
  72. async renderBulkActionTrigger(showInDropdown, index) {
  73. return Templates.render('mod_assign/bulkactions/grading/bulk_setmarkingallocation_trigger', {
  74. showindropdown: showInDropdown,
  75. isfirst: index === 0,
  76. });
  77. }
  78. }