Skip to content

Commit

Permalink
MDL-68463 report_participants: Use new shared participant actions module
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 18, 2020
1 parent bae72dd commit 0d01f2a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
2 changes: 2 additions & 0 deletions report/participation/amd/build/participants.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions report/participation/amd/build/participants.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions report/participation/amd/src/participants.js
@@ -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();
};
2 changes: 1 addition & 1 deletion report/participation/index.php
Expand Up @@ -385,7 +385,7 @@
$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";
}
Expand Down

0 comments on commit 0d01f2a

Please sign in to comment.