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:
11
api.php
11
api.php
@@ -4990,14 +4990,19 @@ switch ($action) {
|
|||||||
$input = json_decode(file_get_contents('php://input'), true);
|
$input = json_decode(file_get_contents('php://input'), true);
|
||||||
$type = $input['type'] ?? '';
|
$type = $input['type'] ?? '';
|
||||||
$enabled = (bool)($input['enabled'] ?? false);
|
$enabled = (bool)($input['enabled'] ?? false);
|
||||||
$config = $input['config'] ?? [];
|
$config = $input['config'] ?? null;
|
||||||
if (!$type) { http_response_code(400); echo json_encode(['error' => 'Tyyppi puuttuu']); break; }
|
if (!$type) { http_response_code(400); echo json_encode(['error' => 'Tyyppi puuttuu']); break; }
|
||||||
|
|
||||||
|
// Jos config ei lähetetty tai on tyhjä, säilytä vanha config (toggle ei ylikirjoita asetuksia)
|
||||||
|
$old = dbGetIntegration($companyId, $type);
|
||||||
|
if ($config === null || (is_array($config) && empty($config))) {
|
||||||
|
$config = ($old && isset($old['config'])) ? (is_string($old['config']) ? json_decode($old['config'], true) : $old['config']) : [];
|
||||||
|
} else {
|
||||||
// Jos token on maskattua (********), säilytä vanha
|
// Jos token on maskattua (********), säilytä vanha
|
||||||
if (isset($config['token']) && preg_match('/^\*+$/', $config['token'])) {
|
if (isset($config['token']) && preg_match('/^\*+$/', $config['token'])) {
|
||||||
$old = dbGetIntegration($companyId, $type);
|
|
||||||
if ($old && isset($old['config']['token'])) {
|
if ($old && isset($old['config']['token'])) {
|
||||||
$config['token'] = $old['config']['token'];
|
$config['token'] = is_string($old['config']) ? json_decode($old['config'], true)['token'] : $old['config']['token'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
41
script.js
41
script.js
@@ -2623,42 +2623,15 @@ async function showCompanyDetail(id) {
|
|||||||
async function loadCompanyIntegrations() {
|
async function loadCompanyIntegrations() {
|
||||||
try {
|
try {
|
||||||
const integrations = await apiCall('integrations');
|
const integrations = await apiCall('integrations');
|
||||||
|
// Aseta vain checkboxit — konfiguraatio ladataan API-tabissa
|
||||||
// Aseta kaikkien integraatioiden checkboxit
|
|
||||||
['zammad', 'saatavuus_api', 'telegram'].forEach(type => {
|
['zammad', 'saatavuus_api', 'telegram'].forEach(type => {
|
||||||
const integ = integrations.find(i => i.type === type);
|
const integ = integrations.find(i => i.type === type);
|
||||||
const cb = document.querySelector(`#integrations-checkboxes input[data-integration="${type}"]`);
|
const cb = document.querySelector(`#integrations-checkboxes input[data-integration="${type}"]`);
|
||||||
if (cb) cb.checked = integ?.enabled || false;
|
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); }
|
} 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 = []) {
|
function renderCompanyZammadGroups(groups, selectedIds = []) {
|
||||||
const container = document.getElementById('company-zammad-groups');
|
const container = document.getElementById('company-zammad-groups');
|
||||||
if (!groups.length) { container.innerHTML = '<span style="color:#888;">Ei ryhmiä.</span>'; return; }
|
if (!groups.length) { container.innerHTML = '<span style="color:#888;">Ei ryhmiä.</span>'; return; }
|
||||||
@@ -2673,7 +2646,6 @@ function renderCompanyZammadGroups(groups, selectedIds = []) {
|
|||||||
async function saveCompanyZammad() {
|
async function saveCompanyZammad() {
|
||||||
const url = document.getElementById('company-zammad-url').value.trim();
|
const url = document.getElementById('company-zammad-url').value.trim();
|
||||||
const token = document.getElementById('company-zammad-token').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 groupCbs = document.querySelectorAll('.company-zammad-group-cb:checked');
|
||||||
const groupIds = Array.from(groupCbs).map(cb => cb.value);
|
const groupIds = Array.from(groupCbs).map(cb => cb.value);
|
||||||
@@ -2681,7 +2653,7 @@ async function saveCompanyZammad() {
|
|||||||
|
|
||||||
await apiCall('integration_save', 'POST', {
|
await apiCall('integration_save', 'POST', {
|
||||||
type: 'zammad',
|
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 },
|
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: {} });
|
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() {
|
document.querySelector('#integrations-checkboxes input[data-integration="zammad"]')?.addEventListener('change', async function() {
|
||||||
toggleCompanyZammadConfig(this.checked);
|
try {
|
||||||
try { await saveCompanyZammad(); } catch (e) { console.error(e); }
|
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
|
// Saatavuus-API checkbox toggle
|
||||||
|
|||||||
Reference in New Issue
Block a user