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 |
* Javascript module for importing presets.
|
|
|
18 |
*
|
|
|
19 |
* @module mod_bigbluebuttonbn/guest_access_modal
|
|
|
20 |
* @copyright 2022 Blindside Networks Inc
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
import {getString} from 'core/str';
|
|
|
24 |
import ModalForm from 'core_form/modalform';
|
|
|
25 |
import {add as toastAdd, addToastRegion} from 'core/toast';
|
|
|
26 |
import {
|
|
|
27 |
exception as displayException,
|
|
|
28 |
} from 'core/notification';
|
|
|
29 |
const selectors = {
|
|
|
30 |
showGuestAccessButton: '[data-action="show-guest-access"]',
|
|
|
31 |
};
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Intialise the object and click event to show the popup form
|
|
|
35 |
*
|
|
|
36 |
* @param {object} guestInfo
|
|
|
37 |
* @param {string} guestInfo.id
|
|
|
38 |
* @param {string} guestInfo.groupid
|
|
|
39 |
* @param {string} guestInfo.guestjoinurl
|
|
|
40 |
* @param {string} guestInfo.guestpassword
|
|
|
41 |
*/
|
|
|
42 |
export const init = (guestInfo) => {
|
|
|
43 |
const showGuestAccessButton = document.querySelector(selectors.showGuestAccessButton);
|
|
|
44 |
if (showGuestAccessButton === null) {
|
|
|
45 |
return;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
const modalForm = new ModalForm({
|
|
|
49 |
modalConfig: {
|
|
|
50 |
title: getString('guestaccess_title', 'mod_bigbluebuttonbn'),
|
|
|
51 |
large: true,
|
|
|
52 |
},
|
|
|
53 |
args: guestInfo,
|
|
|
54 |
saveButtonText: getString('ok', 'core_moodle'),
|
|
|
55 |
formClass: 'mod_bigbluebuttonbn\\form\\guest_add',
|
|
|
56 |
});
|
|
|
57 |
showGuestAccessButton.addEventListener('click', event => {
|
|
|
58 |
modalForm.show().then(() => {
|
|
|
59 |
addToastRegion(modalForm.modal.getRoot()[0]);
|
|
|
60 |
return true;
|
|
|
61 |
}).catch(displayException);
|
|
|
62 |
modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, (e) => {
|
|
|
63 |
// Remove toast region as if not it will be displayed on the closed modal.
|
|
|
64 |
const modalElement = modalForm.modal.getRoot()[0];
|
|
|
65 |
const regions = modalElement.querySelectorAll('.toast-wrapper');
|
|
|
66 |
regions.forEach((reg) => reg.remove());
|
|
|
67 |
if (e.detail.result) {
|
|
|
68 |
if (e.detail.emailcount > 0) {
|
|
|
69 |
toastAdd(getString('guestaccess_invite_success', 'mod_bigbluebuttonbn', e.detail),
|
|
|
70 |
{
|
|
|
71 |
type: 'success',
|
|
|
72 |
}
|
|
|
73 |
);
|
|
|
74 |
}
|
|
|
75 |
} else {
|
|
|
76 |
toastAdd(getString('guestaccess_invite_failure', 'mod_bigbluebuttonbn', e.detail),
|
|
|
77 |
{
|
|
|
78 |
type: 'warning',
|
|
|
79 |
}
|
|
|
80 |
);
|
|
|
81 |
}
|
|
|
82 |
}, {once: true});
|
|
|
83 |
event.stopPropagation();
|
|
|
84 |
});
|
|
|
85 |
};
|