Integraatiot: checkboxit vain päälle/pois Yrityksissä, kaikki asetukset API-tabissa
- Yritykset-tab: integraatio-checkboxit tallentavat vain enabled-tilan - API-tab: Zammad/Saatavuus/Telegram kortit näkyvät kun integraatio päällä - Zammad-asetukset (URL, token, ryhmät, synkronointi) kokonaan API-tabissa - integration_save: tyhjä config ei ylikirjoita olemassaolevia asetuksia Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
41
script.js
41
script.js
@@ -2623,42 +2623,15 @@ async function showCompanyDetail(id) {
|
||||
async function loadCompanyIntegrations() {
|
||||
try {
|
||||
const integrations = await apiCall('integrations');
|
||||
|
||||
// Aseta kaikkien integraatioiden checkboxit
|
||||
// Aseta vain checkboxit — konfiguraatio ladataan API-tabissa
|
||||
['zammad', 'saatavuus_api', 'telegram'].forEach(type => {
|
||||
const integ = integrations.find(i => i.type === type);
|
||||
const cb = document.querySelector(`#integrations-checkboxes input[data-integration="${type}"]`);
|
||||
if (cb) cb.checked = integ?.enabled || false;
|
||||
});
|
||||
|
||||
// Zammad-config näkyvyys
|
||||
const zammad = integrations.find(i => i.type === 'zammad');
|
||||
toggleCompanyZammadConfig(zammad?.enabled || false);
|
||||
|
||||
// Zammad-asetukset
|
||||
if (zammad?.config) {
|
||||
document.getElementById('company-zammad-url').value = zammad.config.url || '';
|
||||
document.getElementById('company-zammad-token').value = zammad.config.token || '';
|
||||
if (zammad.config.group_ids && zammad.config.group_names) {
|
||||
renderCompanyZammadGroups(
|
||||
zammad.config.group_names.map((name, i) => ({ id: zammad.config.group_ids[i], name })),
|
||||
zammad.config.group_ids
|
||||
);
|
||||
}
|
||||
} else {
|
||||
document.getElementById('company-zammad-url').value = '';
|
||||
document.getElementById('company-zammad-token').value = '';
|
||||
document.getElementById('company-zammad-groups').innerHTML = '<span style="color:#888;">Tallenna ensin, sitten valitse ryhmät.</span>';
|
||||
}
|
||||
} catch (e) { console.error('loadCompanyIntegrations:', e); }
|
||||
}
|
||||
|
||||
function toggleCompanyZammadConfig(show) {
|
||||
// Zammad-kortti on nyt API-tabissa
|
||||
const card = document.getElementById('settings-zammad-card');
|
||||
if (card) card.style.display = show ? '' : 'none';
|
||||
}
|
||||
|
||||
function renderCompanyZammadGroups(groups, selectedIds = []) {
|
||||
const container = document.getElementById('company-zammad-groups');
|
||||
if (!groups.length) { container.innerHTML = '<span style="color:#888;">Ei ryhmiä.</span>'; return; }
|
||||
@@ -2673,7 +2646,6 @@ function renderCompanyZammadGroups(groups, selectedIds = []) {
|
||||
async function saveCompanyZammad() {
|
||||
const url = document.getElementById('company-zammad-url').value.trim();
|
||||
const token = document.getElementById('company-zammad-token').value.trim();
|
||||
const enabled = document.querySelector('#integrations-checkboxes input[data-integration="zammad"]')?.checked || false;
|
||||
|
||||
const groupCbs = document.querySelectorAll('.company-zammad-group-cb:checked');
|
||||
const groupIds = Array.from(groupCbs).map(cb => cb.value);
|
||||
@@ -2681,7 +2653,7 @@ async function saveCompanyZammad() {
|
||||
|
||||
await apiCall('integration_save', 'POST', {
|
||||
type: 'zammad',
|
||||
enabled,
|
||||
enabled: true, // Jos ollaan API-tabissa säätämässä, integraatio on päällä
|
||||
config: { url, token, group_ids: groupIds, group_names: groupNames },
|
||||
});
|
||||
}
|
||||
@@ -2691,10 +2663,13 @@ async function saveSimpleIntegration(type, enabled) {
|
||||
await apiCall('integration_save', 'POST', { type, enabled, config: {} });
|
||||
}
|
||||
|
||||
// Zammad checkbox toggle
|
||||
// Zammad checkbox toggle (vain enabled päälle/pois, asetukset API-tabissa)
|
||||
document.querySelector('#integrations-checkboxes input[data-integration="zammad"]')?.addEventListener('change', async function() {
|
||||
toggleCompanyZammadConfig(this.checked);
|
||||
try { await saveCompanyZammad(); } catch (e) { console.error(e); }
|
||||
try {
|
||||
await saveSimpleIntegration('zammad', this.checked);
|
||||
const card = document.getElementById('settings-zammad-card');
|
||||
if (card) card.style.display = this.checked ? '' : 'none';
|
||||
} catch (e) { console.error(e); }
|
||||
});
|
||||
|
||||
// Saatavuus-API checkbox toggle
|
||||
|
||||
Reference in New Issue
Block a user