Add admin presence timing settings
This commit is contained in:
@@ -71,6 +71,9 @@ $("#logoutButton").addEventListener("click", async () => {
|
||||
|
||||
$("#settingsButton").addEventListener("click", () => $("#settingsPanel").classList.toggle("hidden"));
|
||||
$("#closeSettingsButton").addEventListener("click", () => $("#settingsPanel").classList.add("hidden"));
|
||||
$("#presenceActiveSeconds").addEventListener("input", markPresenceSettingsDirty);
|
||||
$("#presenceOfflineSeconds").addEventListener("input", markPresenceSettingsDirty);
|
||||
$("#savePresenceSettings").addEventListener("click", savePresenceSettings);
|
||||
$("#adminSoundToggle").addEventListener("click", () => {
|
||||
setAdminSoundMuted(!state.soundMuted);
|
||||
});
|
||||
@@ -522,6 +525,7 @@ function renderSite() {
|
||||
? `Klic ulozeny (${s.translations.openaiApiKeyMasked || "sk-..."})`
|
||||
: "Klic neni ulozeny. Bez nej AI preklady nepobezi.";
|
||||
renderModelOptions(s.translations?.model || "gpt-5-mini");
|
||||
renderPresenceSettings(s.adminPresence || {});
|
||||
renderTelegramSettings(s.telegram || {});
|
||||
}
|
||||
|
||||
@@ -757,6 +761,52 @@ function setOpenAiStatus(message) {
|
||||
$("#openaiApiKeyStatus").textContent = message;
|
||||
}
|
||||
|
||||
function renderPresenceSettings(settings) {
|
||||
const normalized = normalizePresenceSettings(settings);
|
||||
$("#presenceActiveSeconds").value = normalized.activeSeconds;
|
||||
$("#presenceOfflineSeconds").value = normalized.offlineSeconds;
|
||||
setPresenceStatus(`Oranzova: ${normalized.activeSeconds}-${normalized.offlineSeconds} s necinosti.`);
|
||||
}
|
||||
|
||||
function markPresenceSettingsDirty() {
|
||||
const normalized = normalizePresenceSettings({
|
||||
activeSeconds: $("#presenceActiveSeconds").value,
|
||||
offlineSeconds: $("#presenceOfflineSeconds").value
|
||||
});
|
||||
setPresenceStatus(`Neulozeno. Oranzova bude ${normalized.activeSeconds}-${normalized.offlineSeconds} s.`);
|
||||
}
|
||||
|
||||
async function savePresenceSettings() {
|
||||
if (!state.site) return;
|
||||
const normalized = normalizePresenceSettings({
|
||||
activeSeconds: $("#presenceActiveSeconds").value,
|
||||
offlineSeconds: $("#presenceOfflineSeconds").value
|
||||
});
|
||||
setPresenceStatus("Ukladam signalizaci...");
|
||||
const settings = structuredClone(state.site.settings);
|
||||
settings.adminPresence = normalized;
|
||||
await saveSite({ settings, isOnline: state.site.isOnline });
|
||||
renderPresenceSettings(state.site.settings.adminPresence || normalized);
|
||||
await Promise.all([loadConversations(), loadVisitors()]);
|
||||
setPresenceStatus(`Ulozeno. Oranzova: ${normalized.activeSeconds}-${normalized.offlineSeconds} s.`);
|
||||
}
|
||||
|
||||
function normalizePresenceSettings(value = {}) {
|
||||
const activeSeconds = clampNumber(value.activeSeconds, 10, 3600, 30);
|
||||
const offlineSeconds = Math.max(clampNumber(value.offlineSeconds, 20, 7200, 120), activeSeconds + 10);
|
||||
return { activeSeconds, offlineSeconds };
|
||||
}
|
||||
|
||||
function clampNumber(value, min, max, fallback) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number)) return fallback;
|
||||
return Math.min(max, Math.max(min, Math.round(number)));
|
||||
}
|
||||
|
||||
function setPresenceStatus(message) {
|
||||
$("#presenceStatus").textContent = message;
|
||||
}
|
||||
|
||||
function renderTelegramSettings(settings) {
|
||||
$("#telegramEnabled").checked = Boolean(settings.enabled);
|
||||
$("#telegramOperatorName").value = settings.operatorName || "Alex";
|
||||
|
||||
Reference in New Issue
Block a user