Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * Inplace editable module events
18
 *
19
 * @module      core/local/inplace_editable/events
20
 * @copyright   2021 Paul Holden <paulh@moodle.com>
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import {dispatchEvent} from 'core/event_dispatcher';
25
 
26
/**
27
 * Module events
28
 *
29
 * @constant
30
 * @property {String} elementUpdated See {@link event:core/inplace_editable:updated}
31
 * @property {String} elementUpdateFailed See {@link event:core/inplace_editable:updateFailed}
32
 */
33
export const eventTypes = {
34
 
35
    /**
36
     * Event triggered when an element has been updated
37
     *
38
     * @event core/inplace_editable:updated
39
     * @type {CustomEvent}
40
     * @property {HTMLElement} target The element that was updated
41
     * @property {Object} detail
42
     * @property {Object} detail.ajaxreturn The data returned from the update AJAX request
43
     * @property {String} detail.oldvalue The previous value of the element
44
     */
45
    elementUpdated: 'core/inplace_editable:updated',
46
 
47
    /**
48
     * Event triggered when an element update has failed
49
     *
50
     * @event core/inplace_editable:updateFailed
51
     * @type {CustomEvent}
52
     * @property {HTMLElement} target The element that failed to update
53
     * @property {Object} detail
54
     * @property {Object} detail.exception The raised exception
55
     * @property {String} detail.newvalue The intended value of the element
56
     */
57
    elementUpdateFailed: 'core/inplace_editable:updateFailed',
58
};
59
 
60
/**
61
 * Notify element of successful update
62
 *
63
 * @method
64
 * @param {HTMLElement} element The element that was updated
65
 * @param {Object} ajaxreturn The data returned from the update AJAX request
66
 * @param {String} oldvalue The previous value of the element
67
 * @returns {CustomEvent}
68
 * @fires event:core/inplace_editable:updated
69
 */
70
export const notifyElementUpdated = (element, ajaxreturn, oldvalue) => dispatchEvent(
71
    eventTypes.elementUpdated,
72
    {
73
        ajaxreturn,
74
        oldvalue,
75
    },
76
    element
77
);
78
 
79
/**
80
 * Notify element of failed update
81
 *
82
 * @method
83
 * @param {HTMLElement} element The element that failed to update
84
 * @param {Object} exception The raised exception
85
 * @param {String} newvalue The intended value of the element
86
 * @returns {CustomEvent}
87
 * @fires event:core/inplace_editable:updateFailed
88
 */
89
export const notifyElementUpdateFailed = (element, exception, newvalue) => dispatchEvent(
90
    eventTypes.elementUpdateFailed,
91
    {
92
        exception,
93
        newvalue,
94
    },
95
    element,
96
    {
97
        cancelable: true
98
    }
99
);