Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
/**
17
 * Some UI stuff for participants page.
18
 * This is also used by the report/participants/index.php because it has the same functionality.
19
 *
20
 * @module     report_participation/participants
21
 * @copyright  2017 Damyon Wiese
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
import jQuery from 'jquery';
26
import CustomEvents from 'core/custom_interaction_events';
27
import ModalEvents from 'core/modal_events';
28
import Notification from 'core/notification';
29
import {showSendMessage} from 'core_user/local/participants/bulkactions';
30
 
31
const Selectors = {
32
    bulkActionSelect: "#formactionid",
33
    bulkUserSelectedCheckBoxes: "input[data-togglegroup^='participants-table'][data-toggle='slave']:checked",
34
    participantsForm: '#participantsform',
35
};
36
 
37
export const init = () => {
38
    const root = document.querySelector(Selectors.participantsForm);
39
 
40
    /**
41
     * Private method.
42
     *
43
     * @method registerEventListeners
44
     * @private
45
     */
46
    const registerEventListeners = () => {
47
        CustomEvents.define(Selectors.bulkActionSelect, [CustomEvents.events.accessibleChange]);
48
        jQuery(Selectors.bulkActionSelect).on(CustomEvents.events.accessibleChange, e => {
49
            const action = e.target.value;
50
            const checkboxes = root.querySelectorAll(Selectors.bulkUserSelectedCheckBoxes);
51
 
52
            if (action.indexOf('#') !== -1) {
53
                e.preventDefault();
54
 
55
                const ids = [];
56
                checkboxes.forEach(checkbox => {
57
                    ids.push(checkbox.getAttribute('name').replace('user', ''));
58
                });
59
 
60
                if (action === '#messageselect') {
61
                    showSendMessage(ids)
62
                    .then(modal => {
63
                        modal.getRoot().on(ModalEvents.hidden, () => {
64
                            // Focus on the action select when the dialog is closed.
65
                            const bulkActionSelector = root.querySelector(Selectors.bulkActionSelect);
66
                            resetBulkAction(bulkActionSelector);
67
                            bulkActionSelector.focus();
68
                        });
69
 
70
                        return modal;
71
                    })
72
                    .catch(Notification.exception);
73
                }
74
            } else if (action !== '' && checkboxes.length) {
75
                e.target.form().submit();
76
            }
77
 
78
            resetBulkAction(e.target);
79
        });
80
    };
81
 
82
    const resetBulkAction = bulkActionSelect => {
83
        bulkActionSelect.value = '';
84
    };
85
 
86
    registerEventListeners();
87
};