1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * Module to handle AJAX interactions with user private files
19 * @module core_user/private_files
20 * @copyright 2020 Marina Glancy
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 import DynamicForm from 'core_form/dynamicform';
24 import ModalForm from 'core_form/modalform';
25 import {getString} from 'core/str';
26 import {add as addToast} from 'core/toast';
29 * Initialize private files form as AJAX form
31 * @param {String} containerSelector
32 * @param {String} formClass
34 export const initDynamicForm = (containerSelector, formClass) => {
35 const form = new DynamicForm(document.querySelector(containerSelector), formClass);
37 // When form is saved, refresh it to remove validation errors, if any:
38 form.addEventListener(form.events.FORM_SUBMITTED, () => {
40 getString('changessaved')
45 // Reload the page on cancel.
46 form.addEventListener(form.events.CANCEL_BUTTON_PRESSED, () => window.location.reload());
50 * Initialize private files form as Modal form
52 * @param {String} elementSelector
53 * @param {String} formClass
55 export const initModal = (elementSelector, formClass) => {
56 document.querySelector(elementSelector).addEventListener('click', function(e) {
58 const form = new ModalForm({
60 args: {nosubmit: true},
61 modalConfig: {title: getString('privatefilesmanage')},
62 returnFocus: e.target,
64 form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());