| File was renamed from assets/js/dash/Integrations.js |
| | |
| | | return; |
| | | } |
| | | |
| | | console.log('Clicked!'); |
| | | if (e.target.tagName === 'BUTTON' || e.target.closest('button')) { |
| | | e.preventDefault(); |
| | | let target = e.target.tagName === 'BUTTON' ? e.target : e.target.closest('button'); |
| | |
| | | const data = { |
| | | service: service, |
| | | action: action, |
| | | user_id: jvbSettings.currentUser, |
| | | user_id: window.auth.getUser(), |
| | | data: {} |
| | | }; |
| | | if (!isButton) { |
| | |
| | | } |
| | | } |
| | | |
| | | console.log('Sending Data:', data); |
| | | |
| | | // Make API request |
| | | const response = await fetch( |
| | | jvbSettings.api + 'integrations', { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | 'X-WP-Nonce': jvbSettings.nonce |
| | | 'X-WP-Nonce': window.auth.getNonce() |
| | | }, |
| | | body: JSON.stringify(data) |
| | | }); |
| | |
| | | this.showNotification('Settings saved successfully', 'success'); |
| | | break; |
| | | } |
| | | console.log(result); |
| | | this.updateUI(form, status); |
| | | |
| | | if (result.reload) { |
| | |
| | | }, 50); |
| | | } |
| | | } else { |
| | | console.log (result); |
| | | this.updateUI(form, 'error', result.message??''); |
| | | this.showNotification(result.message || 'Operation failed', 'error'); |
| | | } |
| | |
| | | { |
| | | let allowed = ['connected', 'disconnected', 'hasChanges', 'syncing', 'error']; |
| | | if (!allowed.includes(state)) { |
| | | console.log('Invalid state: ', state); |
| | | return; |
| | | } |
| | | let defaults = { |
| | |
| | | |
| | | form.classList.remove(...allowed); |
| | | form.classList.add(state, 'flash'); |
| | | console.log(form); |
| | | let status = form.querySelector('.setup .text'); |
| | | console.log(status); |
| | | status.textContent = message; |
| | | // Enable/disable buttons |
| | | if (state === 'syncing') { |
| | |
| | | // Add popup indicator to URL |
| | | url += (url.indexOf('?') > -1 ? '&' : '?') + 'popup=1'; |
| | | |
| | | console.log('Opening OAuth popup for', service, 'with URL:', url); |
| | | |
| | | const popup = window.open( |
| | | url, |
| | |
| | | |
| | | // Set up listener for OAuth completion |
| | | window.jvbOAuthComplete = function(completedService, success, message) { |
| | | console.log('OAuth complete:', completedService, success, message); |
| | | |
| | | if (completedService === service) { |
| | | if (success) { |
| | | // Show success message |
| | |
| | | try { |
| | | if (popup.closed) { |
| | | clearInterval(checkPopup); |
| | | console.log('OAuth popup closed'); |
| | | // Refresh anyway in case auth completed |
| | | setTimeout(() => { |
| | | jvbRefreshIntegration(service); |
| | |
| | | |
| | | // Refresh integration display |
| | | window.jvbRefreshIntegration = function(service) { |
| | | console.log('Refreshing integration:', service); |
| | | |
| | | // Use your REST API to check connection status |
| | | fetch(jvbSettings.api + 'integrations', { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | 'X-WP-Nonce': jvbSettings.nonce |
| | | 'X-WP-Nonce': window.auth.getNonce() |
| | | }, |
| | | body: JSON.stringify({ |
| | | service: service, |
| | |
| | | location.reload(); |
| | | }); |
| | | }; |
| | | |
| | | document.addEventListener('DOMContentLoaded', async function() { |
| | | window.auth.subscribe((event) => { |
| | | if (event === 'auth-loaded') { |
| | | window.integrations = new IntegrationsManager(); |
| | | } |
| | | }); |
| | | }); |
| | | |