Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
2
 * Tour management code.
3
 *
4
 * @module     tool_usertours/managetours
5
 * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
6
 */
7
import {prefetchStrings} from 'core/prefetch';
8
import {getString} from 'core/str';
9
import {confirm as confirmModal} from 'core/notification';
10
 
11
/**
12
 * Handle tour management actions.
13
 *
14
 * @param   {Event} e
15
 * @private
16
 */
17
const removeTourHandler = e => {
18
    const deleteButton = e.target.closest('[data-action="delete"]');
19
    if (deleteButton) {
20
        e.preventDefault();
21
        removeTourFromLink(deleteButton.href);
22
    }
23
};
24
 
25
/**
26
 * Handle removal of a tour with confirmation.
27
 *
28
 * @param {string} targetUrl
29
 * @private
30
 */
31
const removeTourFromLink = targetUrl => {
32
    confirmModal(
33
        getString('confirmtourremovaltitle', 'tool_usertours'),
34
        getString('confirmtourremovalquestion', 'tool_usertours'),
35
        getString('yes', 'core'),
36
        getString('no', 'core'),
37
        () => {
38
            window.location = targetUrl;
39
        }
40
    );
41
};
42
 
43
/**
44
 * Set up the tour management handlers.
45
 */
46
export const setup = () => {
47
    prefetchStrings('tool_usertours', [
48
        'confirmtourremovaltitle',
49
        'confirmtourremovalquestion',
50
    ]);
51
 
52
    prefetchStrings('core', [
53
        'yes',
54
        'no',
55
    ]);
56
 
57
    document.querySelector('body').addEventListener('click', removeTourHandler);
58
};