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 saving a new template.
18
 *
19
 * @module      mod_feedback/createtemplate
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
import {add as addToast} from 'core/toast';
28
 
29
const selectors = {
30
    modaltrigger: '[data-action="createtemplate"]',
31
};
32
 
33
/**
34
 * Initialize module
35
 */
36
export const init = () => {
37
    const trigger = document.querySelector(selectors.modaltrigger);
38
 
39
    trigger.addEventListener('click', event => {
40
        event.preventDefault();
41
        const ele = event.currentTarget;
42
 
43
        const modalForm = new ModalForm({
44
            modalConfig: {
45
                title: getString('save_as_new_template', 'mod_feedback'),
46
            },
47
            formClass: 'mod_feedback\\form\\create_template_form',
48
            args: {
49
                id: ele.dataset.dataid
50
            },
51
            saveButtonText: getString('save', 'core')
52
        });
53
 
54
        // Show a toast notification when the form is submitted.
55
        modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {
56
            if (event.detail.result) {
57
                getString('template_saved', 'feedback').then(addToast).catch();
58
            } else {
59
                getString('saving_failed', 'feedback').then(string => {
60
                    return Notification.addNotification({
61
                        type: 'error',
62
                        message: string
63
                    });
64
                }).catch();
65
            }
66
        });
67
 
68
        modalForm.show();
69
    });
70
};