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
import ModalForm from 'core_form/modalform';
17
import {getString} from 'core/str';
18
 
19
/**
20
 * User profile fields editor
21
 *
22
 * @module     core_user/edit_profile_fields
23
 * @copyright  2021 Marina Glancy
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
const Selectors = {
28
    actions: {
29
        editCategory: '[data-action="editcategory"]',
30
        editField: '[data-action="editfield"]',
31
        createField: '[data-action="createfield"]',
32
    },
33
};
34
 
35
export const init = () => {
36
    document.addEventListener('click', function(e) {
37
        let element = e.target.closest(Selectors.actions.editCategory);
38
        if (element) {
39
            e.preventDefault();
40
            const title = element.getAttribute('data-id') ?
41
                getString('profileeditcategory', 'admin', element.getAttribute('data-name')) :
42
                getString('profilecreatenewcategory', 'admin');
43
            const form = new ModalForm({
44
                formClass: 'core_user\\form\\profile_category_form',
45
                args: {id: element.getAttribute('data-id')},
46
                modalConfig: {title},
47
                returnFocus: element,
48
            });
49
            form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
50
            form.show();
51
        }
52
 
53
        element = e.target.closest(Selectors.actions.editField);
54
        if (element) {
55
            e.preventDefault();
56
            const form = new ModalForm({
57
                formClass: 'core_user\\form\\profile_field_form',
58
                args: {id: element.getAttribute('data-id')},
59
                modalConfig: {title: getString('profileeditfield', 'admin', element.getAttribute('data-name'))},
60
                returnFocus: element,
61
            });
62
            form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
63
            form.show();
64
        }
65
 
66
        element = e.target.closest(Selectors.actions.createField);
67
        if (element) {
68
            e.preventDefault();
69
            const form = new ModalForm({
70
                formClass: 'core_user\\form\\profile_field_form',
71
                args: {datatype: element.getAttribute('data-datatype'), categoryid: element.getAttribute('data-categoryid')},
72
                modalConfig: {title: getString('profilecreatenewfield', 'admin', element.getAttribute('data-datatypename'))},
73
                returnFocus: element,
74
            });
75
            form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
76
            form.show();
77
        }
78
    });
79
};