MDL-68463 report_participants: Use new shared participant actions module
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 18 May 2020 02:16:55 +0000 (10:16 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 18 May 2020 12:00:47 +0000 (20:00 +0800)
report/participation/amd/build/participants.min.js [new file with mode: 0644]
report/participation/amd/build/participants.min.js.map [new file with mode: 0644]
report/participation/amd/src/participants.js [new file with mode: 0644]
report/participation/index.php

diff --git a/report/participation/amd/build/participants.min.js b/report/participation/amd/build/participants.min.js
new file mode 100644 (file)
index 0000000..fa9364b
Binary files /dev/null and b/report/participation/amd/build/participants.min.js differ
diff --git a/report/participation/amd/build/participants.min.js.map b/report/participation/amd/build/participants.min.js.map
new file mode 100644 (file)
index 0000000..23f6cb6
Binary files /dev/null and b/report/participation/amd/build/participants.min.js.map differ
diff --git a/report/participation/amd/src/participants.js b/report/participation/amd/src/participants.js
new file mode 100644 (file)
index 0000000..7af7b60
--- /dev/null
@@ -0,0 +1,88 @@
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Some UI stuff for participants page.
+ * This is also used by the report/participants/index.php because it has the same functionality.
+ *
+ * @module     core_user/participants
+ * @package    core_user
+ * @copyright  2017 Damyon Wiese
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+import jQuery from 'jquery';
+import CustomEvents from 'core/custom_interaction_events';
+import ModalEvents from 'core/modal_events';
+import Notification from 'core/notification';
+import {showSendMessage} from 'core_user/local/participants/bulkactions';
+
+const Selectors = {
+    bulkActionSelect: "#formactionid",
+    bulkUserSelectedCheckBoxes: "input[data-togglegroup^='participants-table']:checked",
+    participantsForm: '#participantsform',
+};
+
+export const init = () => {
+    const root = document.querySelector(Selectors.participantsForm);
+
+    /**
+     * Private method.
+     *
+     * @method registerEventListeners
+     * @private
+     */
+    const registerEventListeners = () => {
+        CustomEvents.define(Selectors.bulkActionSelect, [CustomEvents.events.accessibleChange]);
+        jQuery(Selectors.bulkActionSelect).on(CustomEvents.events.accessibleChange, e => {
+            const action = e.target.value;
+            const checkboxes = root.querySelectorAll(Selectors.bulkUserSelectedCheckBoxes);
+
+            if (action.indexOf('#') !== -1) {
+                e.preventDefault();
+
+                const ids = [];
+                checkboxes.forEach(checkbox => {
+                    ids.push(checkbox.getAttribute('name').replace('user', ''));
+                });
+
+                if (action === '#messageselect') {
+                    showSendMessage(ids)
+                    .then(modal => {
+                        modal.getRoot().on(ModalEvents.hidden, () => {
+                            // Focus on the action select when the dialog is closed.
+                            const bulkActionSelector = root.querySelector(Selectors.bulkActionSelect);
+                            resetBulkAction(bulkActionSelector);
+                            bulkActionSelector.focus();
+                        });
+
+                        return modal;
+                    })
+                    .catch(Notification.exception);
+                }
+            } else if (action !== '' && checkboxes.length) {
+                e.target.form().submit();
+            }
+
+            resetBulkAction(e.target);
+        });
+    };
+
+    const resetBulkAction = bulkActionSelect => {
+        bulkActionSelect.value = '';
+    };
+
+    registerEventListeners();
+};
index 4101947..ef7a617 100644 (file)
@@ -385,7 +385,7 @@ if (!empty($instanceid) && !empty($roleid)) {
         $options->courseid = $course->id;
         $options->noteStateNames = note_get_state_names();
         $options->stateHelpIcon = $OUTPUT->help_icon('publishstate', 'notes');
-        $PAGE->requires->js_call_amd('core_user/participants', 'init', [$options]);
+        $PAGE->requires->js_call_amd('report_participation/participants', 'init', [$options]);
     }
     echo '</div>'."\n";
 }