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
 * Report builder card view editor
18
 *
19
 * @module      core_reportbuilder/local/editor/card_view
20
 * @copyright   2021 Mikel Martín <mikel@moodle.com>
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
"use strict";
25
 
26
import DynamicForm from 'core_form/dynamicform';
27
import {add as addToast} from 'core/toast';
28
import {getString} from "core/str";
29
import {subscribe as subscribe} from 'core/pubsub';
30
import Notification from 'core/notification';
31
import * as reportEvents from 'core_reportbuilder/local/events';
32
import * as reportSelectors from 'core_reportbuilder/local/selectors';
33
 
34
let cardViewForm = null;
35
 
36
/**
37
 * Initialise card view form, must be called on each init because the form container is re-created when switching editor modes
38
 */
39
const initCardViewForm = () => {
40
    const cardViewFormContainer = document.querySelector(reportSelectors.regions.settingsCardView);
41
    if (!cardViewFormContainer) {
42
        return;
43
    }
44
    cardViewForm = new DynamicForm(cardViewFormContainer, '\\core_reportbuilder\\form\\card_view');
45
 
46
    cardViewForm.addEventListener(cardViewForm.events.FORM_SUBMITTED, (event) => {
47
        event.preventDefault();
48
 
49
        getString('cardviewsettingssaved', 'core_reportbuilder')
50
            .then(addToast)
51
            .catch(Notification.exception);
52
    });
53
};
54
 
55
/**
56
 * Initialise module
57
 *
58
 * @param {Boolean} initialized Ensure we only add our listeners once
59
 */
60
export const init = (initialized) => {
61
    initCardViewForm();
62
    if (initialized) {
63
        return;
64
    }
65
 
66
    // Update form each time a column is added or removed to the custom report.
67
    subscribe(reportEvents.publish.reportColumnsUpdated, () => {
68
        const reportElement = document.querySelector(reportSelectors.regions.report);
69
        cardViewForm.load({reportid: reportElement.dataset.reportId});
70
    });
71
};