-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy pathRequestPanel.js
More file actions
41 lines (37 loc) · 904 Bytes
/
RequestPanel.js
File metadata and controls
41 lines (37 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export default (($) => {
const addMessage = (text) => {
$(`<p>${text}</p>`)
.appendTo('.c-request-panel__messages')
.fadeOut(2000);
};
const init = () => {
$('.js-clear-session').on('click', function triggerSessionClear(e) {
const el = $(this);
const baseUrl = el.attr('data-url');
const csrf = el.attr('data-csrf');
$.ajax({
headers: { 'X-CSRF-TOKEN': csrf },
url: baseUrl,
dataType: 'json',
type: 'POST',
success(data) {
addMessage(data.message);
},
error(jqXHR, textStatus, errorThrown) {
addMessage(errorThrown);
},
});
e.preventDefault();
});
};
const onEvent = () => {
document.addEventListener('initPanel', (e) => {
if (e.detail === 'panelrequest') {
init();
}
});
};
return {
onEvent,
};
})(jQuery);