(function() { 'use strict'; const saveButton = document.getElementById('analytics-hub-save'); const testButton = document.getElementById('analytics-hub-test'); if (saveButton) { saveButton.addEventListener('click', function() { // Collect form data const data = { google_client_id: document.getElementById('google_client_id').value, google_client_secret: document.getElementById('google_client_secret').value, google_refresh_token: document.getElementById('google_refresh_token').value, anthropic_api_key: document.getElementById('anthropic_api_key').value }; // Send save request fetch(OC.generateUrl('/apps/analyticshub/admin/save'), { method: 'POST', headers: { 'Content-Type': 'application/json', 'requesttoken': OC.requestToken }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (data.success) { OC.Notification.showTemporary(t('analyticshub', 'Configuration saved successfully')); } else { OC.Notification.showTemporary(t('analyticshub', 'Error: ' + data.error)); } }) .catch(error => { OC.Notification.showTemporary(t('analyticshub', 'Error saving configuration')); }); }); } if (testButton) { testButton.addEventListener('click', function() { // Test connections fetch(OC.generateUrl('/apps/analyticshub/admin/status'), { method: 'GET', headers: { 'requesttoken': OC.requestToken } }) .then(response => response.json()) .then(data => { if (data.success) { const status = data.data; const message = [ 'App Status: ' + status.status, 'Google Analytics: ' + status.google_analytics, 'LLM Service: ' + status.llm_service ].join('\n'); alert(message); } }) .catch(error => { OC.Notification.showTemporary(t('analyticshub', 'Error getting status')); }); }); } })();