PluginProbe
seQura / 2.0.12
seQura v2.0.12
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / assets / js / logs.js

logs.js in seQura 2.0.12, at assets/js/logs.js

105 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 Logs = {
3 init: function () {
4 this.content = document.getElementById('sequra-logs-content');
5 this.contentTitle = document.querySelector('.sequra-logs__title');
6 this.contentError = document.querySelector('.sequra-logs__error');
7 this.contentSuccess = document.querySelector('.sequra-logs__success');
8 this.reload = document.getElementById('sequra-logs-reload');
9 this.clear = document.getElementById('sequra-logs-clear');
10 this.dialog = document.querySelector('.sequra-modal');
11
12 this.bindEvents();
13 this.handleLoad();
14 },
15 bindEvents: function () {
16 this.reload.addEventListener('click', this.handleLoad.bind(this));
17 this.clear.addEventListener('click', this.handleClearConfirmation.bind(this));
18
19 this.dialog.querySelector('.sequra-modal__ko').addEventListener('click', () => this.dialog.close());
20 this.dialog.querySelector('.sequra-modal__ok').addEventListener('click', this.handleClear.bind(this));
21 },
22
23 updateDom: function (args) {
24 const isLoading = args?.isLoading || false;
25
26 this.contentError.textContent = args?.error || '';
27 this.contentSuccess.textContent = args?.success || '';
28
29 if (isLoading) {
30 this.contentTitle.textContent = 'Loading...';
31 this.content.classList.remove('active');
32 this.content.value = '';
33 return
34 }
35
36 this.contentTitle.textContent = 'Logs';
37
38 if ('undefined' !== typeof args.content) {
39 this.content.value = args.content;
40 }
41
42 if (this.content.value) {
43 this.content.classList.add('active');
44 } else {
45 this.content.classList.remove('active');
46 }
47
48 },
49
50 ajax: function (args) {
51 return fetch(sequraLogs.url, {
52 mode: 'same-origin',
53 method: args?.method || 'GET',
54 headers: {
55 'Content-Type': 'application/json',
56 'X-WP-Nonce': sequraLogs.nonce
57 },
58 })
59 },
60
61 handleLoad: function () {
62 this.updateDom({ isLoading: true });
63 this.ajax()
64 .then(response => {
65 if (!response.ok) {
66 // decode the response body
67 return response.json().then(text => {
68 throw new Error(text?.message || response.statusText);
69 });
70 }
71 return response.text()
72 })
73 .then(data => {
74 this.updateDom({ success: '', content: data })
75 })
76 .catch(e => {
77 this.updateDom({ error: e.message || 'Error loading logs' })
78 })
79 },
80
81 handleClearConfirmation: function () {
82 this.dialog.showModal();
83 },
84 handleClear: function () {
85 this.dialog.close()
86 this.updateDom({ isLoading: true });
87
88 this.ajax({ method: 'DELETE' })
89 .then(response => {
90 if (!response.ok) {
91 throw new Error(response.statusText);
92 }
93 return response.json()
94 })
95 .then(data => {
96 this.updateDom({ success: data.message || 'Logs deleted', content: '' })
97 })
98 .catch(e => {
99 this.updateDom({ error: e.message || 'Error clearing logs' })
100 })
101 },
102 };
103
104 Logs.init();
105 })();