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
 * Javascript module for using an existing template
18
 *
19
 * @module      mod_feedback/usetemplate
20
 * @copyright   2021 Peter Dias
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 Notification from 'core/notification';
26
import {getString} from 'core/str';
27
 
28
const selectors = {
29
    modaltrigger: '[data-action="usetemplate"]',
30
};
31
 
32
/**
33
 * Initialize module
34
 */
35
export const init = () => {
36
    const trigger = document.querySelector(selectors.modaltrigger);
37
 
38
    trigger.addEventListener('click', event => {
39
        event.preventDefault();
40
 
41
        const modalForm = new ModalForm({
42
            modalConfig: {
43
                title: getString('use_this_template', 'mod_feedback'),
44
            },
45
            formClass: 'mod_feedback\\form\\use_template_form',
46
            args: {
47
                id: trigger.getAttribute('data-dataid'),
48
                templateid: trigger.getAttribute('data-templateid')
49
            },
50
            saveButtonText: getString('save', 'core')
51
        });
52
 
53
        // Show a toast notification when the form is submitted.
54
        modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {
55
            if (event.detail.result) {
56
                window.location.assign(event.detail.url);
57
            } else {
58
                Notification.addNotification({
59
                    type: 'error',
60
                    message:  getString('saving_failed', 'mod_feedback')
61
                });
62
            }
63
        });
64
 
65
        modalForm.show();
66
    });
67
};