Add module visibility fix and configurable postal codes for saatavuus API
- Add 'hallinta' to ALL_MODULES so it appears in company settings - Change fallback from ALL_MODULES to DEFAULT_MODULES (new modules not enabled by default) - Hallinta tab requires both module enabled + superadmin role - Add per-company configurable postal codes for "todennäköinen" availability - Saatavuus API returns true/todennäköinen/false based on customer data + postal codes - Show "Todennäköinen" badge in availability queries list Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
20
script.js
20
script.js
@@ -2744,6 +2744,7 @@ async function loadSettings() {
|
||||
const config = await apiCall('config');
|
||||
document.getElementById('settings-api-key').value = config.api_key || '';
|
||||
document.getElementById('settings-cors').value = (config.cors_origins || []).join('\n');
|
||||
document.getElementById('settings-probable-postcodes').value = (config.probable_postcodes || []).join('\n');
|
||||
// Näytä yrityksen nimi API-otsikossa
|
||||
const apiTitle = document.getElementById('api-company-name');
|
||||
if (apiTitle && currentCompany) apiTitle.textContent = currentCompany.nimi + ' — ';
|
||||
@@ -2831,6 +2832,7 @@ document.getElementById('btn-save-settings').addEventListener('click', async ()
|
||||
const config = await apiCall('config_update', 'POST', {
|
||||
api_key: document.getElementById('settings-api-key').value,
|
||||
cors_origins: document.getElementById('settings-cors').value,
|
||||
probable_postcodes: document.getElementById('settings-probable-postcodes').value,
|
||||
});
|
||||
alert('Asetukset tallennettu!');
|
||||
} catch (e) { alert(e.message); }
|
||||
@@ -3737,9 +3739,11 @@ async function loadAvailabilityQueries(page = 0) {
|
||||
} else {
|
||||
tbody.innerHTML = data.queries.map(q => {
|
||||
const date = q.created_at ? q.created_at.replace('T', ' ').substring(0, 16) : '';
|
||||
const found = q.saatavilla == 1;
|
||||
const badge = found
|
||||
const saatVal = parseInt(q.saatavilla);
|
||||
const badge = saatVal === 1
|
||||
? '<span style="background:#e8f5e9;color:#2e7d32;padding:2px 8px;border-radius:10px;font-size:0.8rem;">Saatavilla</span>'
|
||||
: saatVal === 2
|
||||
? '<span style="background:#fff3e0;color:#e65100;padding:2px 8px;border-radius:10px;font-size:0.8rem;">Todennäköinen</span>'
|
||||
: '<span style="background:#fce4ec;color:#c62828;padding:2px 8px;border-radius:10px;font-size:0.8rem;">Ei saatavilla</span>';
|
||||
let source = '';
|
||||
if (q.referer) {
|
||||
@@ -6719,7 +6723,7 @@ document.getElementById('laitetila-edit-form')?.addEventListener('submit', async
|
||||
|
||||
// ==================== MODUULIT ====================
|
||||
|
||||
const ALL_MODULES = ['customers', 'support', 'leads', 'tekniikka', 'ohjeet', 'todo', 'documents', 'laitetilat', 'netadmin', 'archive', 'changelog', 'settings'];
|
||||
const ALL_MODULES = ['customers', 'support', 'leads', 'tekniikka', 'ohjeet', 'todo', 'documents', 'laitetilat', 'netadmin', 'hallinta', 'archive', 'changelog', 'settings'];
|
||||
const DEFAULT_MODULES = ['customers', 'support', 'archive', 'changelog', 'settings'];
|
||||
|
||||
function applyModules(modules, hasIntegrations) {
|
||||
@@ -6727,8 +6731,8 @@ function applyModules(modules, hasIntegrations) {
|
||||
if (modules && modules.includes('devices') && !modules.includes('tekniikka')) {
|
||||
modules = modules.map(m => m === 'devices' ? 'tekniikka' : m);
|
||||
}
|
||||
// Jos tyhjä array → kaikki moduulit päällä (fallback)
|
||||
const enabled = (modules && modules.length > 0) ? modules : ALL_MODULES;
|
||||
// Jos tyhjä array → oletusmoduulit (admin aktivoi uudet erikseen)
|
||||
const enabled = (modules && modules.length > 0) ? modules : DEFAULT_MODULES;
|
||||
const isAdminUser = isCurrentUserAdmin();
|
||||
const isSuperAdmin = currentUser?.role === 'superadmin';
|
||||
ALL_MODULES.forEach(mod => {
|
||||
@@ -6738,14 +6742,14 @@ function applyModules(modules, hasIntegrations) {
|
||||
if (mod === 'settings') {
|
||||
const showSettings = enabled.includes(mod) && isAdminUser && (isSuperAdmin || hasIntegrations === true);
|
||||
tabBtn.style.display = showSettings ? '' : 'none';
|
||||
// hallinta: vain superadmineille + pitää olla moduulina päällä
|
||||
} else if (mod === 'hallinta') {
|
||||
tabBtn.style.display = (enabled.includes(mod) && isSuperAdmin) ? '' : 'none';
|
||||
} else {
|
||||
tabBtn.style.display = enabled.includes(mod) ? '' : 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
// Hallinta-tabi: aina näkyvä superadmineille, ei moduuliriippuvuutta
|
||||
const hallintaTab = document.getElementById('tab-hallinta');
|
||||
if (hallintaTab) hallintaTab.style.display = isSuperAdmin ? '' : 'none';
|
||||
// Jos aktiivinen tabi on piilotettu → vaihda ensimmäiseen näkyvään
|
||||
const activeTab = document.querySelector('.tab.active');
|
||||
if (activeTab && activeTab.style.display === 'none') {
|
||||
|
||||
Reference in New Issue
Block a user