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
 * AMD module to enable users to manage their own data requests.
18
 *
19
 * @module     tool_dataprivacy/myrequestactions
20
 * @copyright  2018 Jun Pataleta
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import Ajax from 'core/ajax';
25
import Notification from 'core/notification';
26
import Pending from 'core/pending';
27
import {getStrings} from 'core/str';
28
 
29
const SELECTORS = {
30
    CANCEL_REQUEST: '[data-action="cancel"][data-requestid]',
31
};
32
 
33
/**
34
 * Initialize module
35
 */
36
export const init = () => {
37
    document.addEventListener('click', event => {
38
        const triggerElement = event.target.closest(SELECTORS.CANCEL_REQUEST);
39
        if (triggerElement === null) {
40
            return;
41
        }
42
 
43
        event.preventDefault();
44
 
45
        const requiredStrings = [
46
            {key: 'cancelrequest', component: 'tool_dataprivacy'},
47
            {key: 'cancelrequestconfirmation', component: 'tool_dataprivacy'},
48
        ];
49
 
50
        getStrings(requiredStrings).then(([cancelRequest, cancelConfirm]) => {
51
            return Notification.confirm(cancelRequest, cancelConfirm, cancelRequest, null, () => {
52
                const pendingPromise = new Pending('tool/dataprivacy:cancelRequest');
53
                const request = {
54
                    methodname: 'tool_dataprivacy_cancel_data_request',
55
                    args: {requestid: triggerElement.dataset.requestid}
56
                };
57
 
58
                Ajax.call([request])[0].then(response => {
59
                    if (response.result) {
60
                        window.location.reload();
61
                    } else {
62
                        Notification.addNotification({
63
                            type: 'error',
64
                            message: response.warnings[0].message
65
                        });
66
                    }
67
                    return pendingPromise.resolve();
68
                }).catch(Notification.exception);
69
            });
70
        }).catch();
71
    });
72
};