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 editing blocks
|
|
|
18 |
*
|
|
|
19 |
* @module core_block/edit
|
|
|
20 |
* @copyright 2022 Marina Glancy
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import ModalForm from 'core_form/modalform';
|
|
|
25 |
|
|
|
26 |
const SELECTORS = {
|
|
|
27 |
EDITBLOCK: '[data-action="editblock"][data-blockid][data-blockform]',
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Initialize module
|
|
|
32 |
* @param {String} pagehash
|
|
|
33 |
*/
|
|
|
34 |
export const init = (pagehash) => {
|
|
|
35 |
document.addEventListener('click', e => {
|
|
|
36 |
const target = e.target.closest(SELECTORS.EDITBLOCK);
|
|
|
37 |
if (!target || !target.getAttribute('data-blockform')) {
|
|
|
38 |
return;
|
|
|
39 |
}
|
|
|
40 |
e.preventDefault();
|
|
|
41 |
|
|
|
42 |
const modalForm = new ModalForm({
|
|
|
43 |
modalConfig: {
|
|
|
44 |
title: target.getAttribute('data-header'),
|
|
|
45 |
},
|
|
|
46 |
args: {blockid: target.getAttribute('data-blockid'), pagehash},
|
|
|
47 |
formClass: target.getAttribute('data-blockform'),
|
|
|
48 |
returnFocus: target,
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
// Reload the page when the form is submitted, there is no possibility
|
|
|
52 |
// currently to request contents update of just one block on the page.
|
|
|
53 |
modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, () => {
|
|
|
54 |
location.reload();
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
modalForm.show();
|
|
|
58 |
});
|
|
|
59 |
};
|