PluginProbe ʕ •ᴥ•ʔ
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback / 5.1
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback v5.1
5.1.3 5.1.2 5.1.1 5.1 5.0 trunk 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.2.0 3.2.1 3.22 3.22.1 3.22.2 3.22.3 3.22.4 3.22.5 3.22.6 3.3.0 3.3.1 3.3.2 3.3.2.1 3.3.2.2 3.3.3 3.30 3.31 3.32 3.4 3.4.1 3.4.3 3.4.4 3.5 3.5.1 3.6 3.6.1 3.7 3.8 3.9 3.9.1 3.9.2 3.9.3 3.9.4 3.9.6 3.9.6.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2 4.2.1 4.2.2 4.3 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4
atarim-visual-collaboration / assets / js / global.js
atarim-visual-collaboration / assets / js Last commit date
admin.js 3 weeks ago global.js 3 weeks ago
global.js
146 lines
1 class ConsentFormHandler {
2 constructor() {
3 this.initializeEventListeners();
4 }
5
6 initializeEventListeners() {
7 document.addEventListener('click', (e) => {
8 if (e.target.closest('.avc_consent_form_launcher')) {
9 this.showConsentForm(e.target.closest('.avc_consent_form_launcher'));
10 }
11 });
12
13 // Close consent form
14 document.addEventListener('click', (e) => {
15 if (e.target.closest('.avc_user_consent_close')) {
16 this.hideConsentForm();
17 }
18 });
19
20 // Handle consent submission
21 document.addEventListener('click', (e) => {
22 if (e.target.closest('.avc_user_consent_button')) {
23 this.handleConsentSubmission(e.target.closest('.avc_user_consent_button'));
24 }
25 });
26 }
27
28 showConsentForm(launcher) {
29 launcher.classList.add('avc_hide_launcher');
30 document.querySelector('.avc_user_consent_container')?.classList.add('avc_show');
31 }
32
33 hideConsentForm() {
34 document.querySelector('.avc_user_consent_container')?.classList.remove('avc_show');
35 }
36
37 async handleConsentSubmission(button) {
38 try {
39 this.setLoadingState(button, true);
40
41 const firstResponse = await this.submitUserConsent();
42
43 if (firstResponse?.data) {
44 await this.makeChainedRequest(firstResponse.data);
45 this.redirectWithConsentParam();
46 } else {
47 throw new Error('Invalid response from consent submission');
48 }
49 } catch (error) {
50 console.error('Consent submission failed:', error);
51 alert('Something went wrong. Please try again.');
52 } finally {
53 this.setLoadingState(button, false);
54 }
55 }
56
57 async submitUserConsent() {
58 const formData = new FormData();
59 formData.append('action', 'avcf_user_consent');
60 formData.append('avc_nonce', window.avc_site_data?.avc_nonce || '');
61
62 const response = await fetch(window.avcajax?.ajaxurl || '/wp-admin/admin-ajax.php', {
63 method: 'POST',
64 body: formData,
65 });
66
67 if (!response.ok) {
68 throw new Error(`HTTP error! status: ${response.status}`);
69 }
70
71 return response.json();
72 }
73
74 async makeChainedRequest(data) {
75 const response = await fetch(data.apiurl, {
76 method: 'POST',
77 headers: {
78 'Content-Type': 'application/json',
79 'api-key': data.apikey,
80 },
81 credentials: 'include',
82 body: JSON.stringify(data),
83 });
84
85 if (!response.ok) {
86 throw new Error(`Chained request failed! status: ${response.status}`);
87 }
88
89 const result = await response.json();
90
91 if (!result) {
92 throw new Error('Second request returned invalid response');
93 }
94
95 await this.setConsentStatusOnServer();
96
97 return result;
98 }
99
100 redirectWithConsentParam() {
101 const currentUrl = new URL(window.location.href);
102 window.location.href = currentUrl.toString();
103 }
104
105 setLoadingState(button, isLoading) {
106 const loader = document.querySelector('.avc_consent_loader');
107
108 if (isLoading) {
109 button.classList.add('loading');
110 loader?.style.setProperty('display', 'block');
111 } else {
112 button.classList.remove('loading');
113 loader?.style.setProperty('display', 'none');
114 }
115 }
116
117 async setConsentStatusOnServer() {
118 const formData = new FormData();
119 formData.append('action', 'avcf_set_user_consent_status');
120 formData.append('avc_nonce', window.avc_site_data?.avc_nonce || '');
121
122 const response = await fetch(window.avcajax?.ajaxurl || '/wp-admin/admin-ajax.php', {
123 method: 'POST',
124 body: formData,
125 credentials: 'include',
126 });
127
128 if (!response.ok) {
129 throw new Error(`Failed to update user meta. Status: ${response.status}`);
130 }
131
132 const result = await response.json();
133 if (!result.success) {
134 throw new Error(result.data?.message || 'Unknown error from consent meta update');
135 }
136 }
137 }
138
139 // Initialize when DOM is ready
140 if (document.readyState === 'loading') {
141 document.addEventListener('DOMContentLoaded', () => {
142 new ConsentFormHandler();
143 });
144 } else {
145 new ConsentFormHandler();
146 }