- Add server-side ticket summary endpoint for exact KPI counts instead of client-side calculation from first 200 tickets - Extract summarizeTickets() as shared static method to avoid duplication - Replace custom .helpdesk-spinner CSS with core [aria-busy] pattern - Migrate settings connection-test feedback to showAsyncFlash() - Replace helpdesk-clickable-rows.js with delegated event handling - Remove unused helpdesk-search.js (dead code, never loaded) - Harmonize German wording: Debitoren → Kunden (8 i18n keys) - Add 6 PHPUnit tests for loadTicketSummary() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
/**
|
|
* Helpdesk settings page — auth mode toggle and connection test.
|
|
*/
|
|
import { showAsyncFlash } from '/js/components/app-async-flash.js';
|
|
|
|
// Toggle OAuth2 vs Basic Auth field visibility
|
|
const authModeSelect = document.getElementById('auth_mode');
|
|
const basicFields = document.getElementById('helpdesk-basic-auth-fields');
|
|
const oauth2Fields = document.getElementById('helpdesk-oauth2-fields');
|
|
|
|
const toggleAuthFields = () => {
|
|
if (!authModeSelect || !basicFields || !oauth2Fields) {
|
|
return;
|
|
}
|
|
const isOAuth2 = authModeSelect.value === 'oauth2';
|
|
basicFields.style.display = isOAuth2 ? 'none' : '';
|
|
oauth2Fields.style.display = isOAuth2 ? '' : 'none';
|
|
};
|
|
|
|
if (authModeSelect) {
|
|
authModeSelect.addEventListener('change', toggleAuthFields);
|
|
toggleAuthFields();
|
|
}
|
|
|
|
// Connection test button
|
|
const testButton = document.getElementById('helpdesk-test-connection-button');
|
|
|
|
if (testButton) {
|
|
testButton.addEventListener('click', async () => {
|
|
testButton.disabled = true;
|
|
testButton.setAttribute('aria-busy', 'true');
|
|
|
|
try {
|
|
const csrfMeta = document.querySelector('meta[name="csrf-token"]');
|
|
const csrfInput = document.querySelector('input[name="csrf_token"]');
|
|
const csrfToken = csrfInput?.value || csrfMeta?.content || '';
|
|
|
|
const formData = new FormData();
|
|
if (csrfToken) {
|
|
formData.append('csrf_token', csrfToken);
|
|
}
|
|
|
|
const response = await fetch(
|
|
new URL('helpdesk/settings/test-connection-data', document.baseURI).href,
|
|
{
|
|
method: 'POST',
|
|
body: formData,
|
|
credentials: 'same-origin',
|
|
},
|
|
);
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.ok) {
|
|
showAsyncFlash('success', data.message || 'Connection successful');
|
|
} else {
|
|
let msg = data.error || 'Connection failed';
|
|
if (data.debug?.http_code) {
|
|
msg += ' (HTTP ' + data.debug.http_code + ')';
|
|
}
|
|
showAsyncFlash('error', msg);
|
|
}
|
|
} catch {
|
|
showAsyncFlash('error', 'Connection failed');
|
|
} finally {
|
|
testButton.disabled = false;
|
|
testButton.removeAttribute('aria-busy');
|
|
}
|
|
});
|
|
}
|