Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
 * Functions for the enrol_self plugin
18
 *
19
 * @module     enrol_self/enrol_page
20
 * @copyright  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
import {getString} from 'core/str';
26
import {prefetchStrings} from 'core/prefetch';
27
import Url from 'core/url';
28
 
29
/**
30
 * Initialise widget on the course enrolment page - clicking on the button should submit the form
31
 *
32
 * @param {Number} instanceId
33
 */
34
export function initEnrol(instanceId) {
35
    prefetchStrings('enrol_self', [
36
        'enrolme',
37
    ]);
38
 
39
    const button = document.querySelector('button[type="submit"][data-instance="' + instanceId + '"]');
40
    if (button) {
41
        button.addEventListener('click', (e) => {
42
            e.preventDefault();
43
            const modalForm = new ModalForm({
44
                modalConfig: {
45
                    title: button.dataset.title,
46
                    large: false, // This is a very small form that does not need a large popup.
47
                },
48
                formClass: button.dataset.form,
49
                args: {id: button.dataset.id, instance: instanceId},
50
                saveButtonText: getString('enrolme', 'enrol_self'),
51
                returnFocus: button,
52
            });
53
 
54
            // Redirect to the course page when the form is submitted.
55
            modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {
56
                window.location.href = event.detail ? event.detail :
57
                    Url.relativeUrl('/course/view.php', {id: button.dataset.id});
58
            });
59
 
60
            modalForm.show();
61
        });
62
    }
63
}