feat(settings): hide push-channel fields when "Nur Dashboard" is picked

Channel-dependent fields (Telegram bot token, chat id, event checkboxes,
"Test senden" button) now hide when the user switches the Kanal select
to "Nur Dashboard". Implemented as data-channel-only="telegram" markers
that a tiny syncChannelOnlyFields() in app.js toggles via inline
display:none. Initial state is set in Jinja so there's no flash on
load.

Hidden inputs stay in the form, so the values survive the round-trip:
switch to Dashboard → save → switch back to Telegram and the bot
token / chat id are still there.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
EiSiMo 2026-04-23 13:50:15 +02:00
parent 6ad6565cf2
commit b759cbb505
2 changed files with 31 additions and 4 deletions

View file

@ -144,6 +144,26 @@ function openDeepLinkedFlat() {
document.addEventListener("DOMContentLoaded", openDeepLinkedFlat); document.addEventListener("DOMContentLoaded", openDeepLinkedFlat);
// Notification-channel toggle — show fields tagged data-channel-only="<value>"
// only while that channel is selected. Hidden inputs stay in the form so
// values survive a round-trip (e.g. switch to "ui", save, switch back to
// "telegram" and the bot token is still there).
function syncChannelOnlyFields() {
const sel = document.querySelector('select[name="channel"]');
if (!sel) return;
const channel = sel.value;
document.querySelectorAll("[data-channel-only]").forEach((el) => {
el.style.display = el.dataset.channelOnly === channel ? "" : "none";
});
}
document.addEventListener("change", (ev) => {
if (ev.target && ev.target.matches && ev.target.matches('select[name="channel"]')) {
syncChannelOnlyFields();
}
});
document.addEventListener("DOMContentLoaded", syncChannelOnlyFields);
document.body && document.body.addEventListener("htmx:afterSwap", syncChannelOnlyFields);
// Image lightbox — single global modal in base.html, opened by clicking any // Image lightbox — single global modal in base.html, opened by clicking any
// .flat-gallery-tile. Click handler is delegated so it survives HTMX swaps. // .flat-gallery-tile. Click handler is delegated so it survives HTMX swaps.
// Visibility is driven by inline style.display rather than a `hidden` class // Visibility is driven by inline style.display rather than a `hidden` class

View file

@ -19,6 +19,11 @@
autocomplete="off" data-lpignore="true" data-1p-ignore data-bwignore data-form-type="other"> autocomplete="off" data-lpignore="true" data-1p-ignore data-bwignore data-form-type="other">
<input type="hidden" name="csrf" value="{{ csrf }}"> <input type="hidden" name="csrf" value="{{ csrf }}">
{# Channel-dependent fields are wrapped in data-channel-only="telegram" so a
small JS handler in app.js can hide them when "Nur Dashboard" is picked.
Inputs stay in the form (display:none doesn't strip them), so values are
preserved when you switch back to Telegram. #}
{% set hide_telegram = notifications.channel != 'telegram' %}
<div> <div>
<label class="block text-xs uppercase text-slate-500 mb-1">Kanal</label> <label class="block text-xs uppercase text-slate-500 mb-1">Kanal</label>
<select class="input" name="channel"> <select class="input" name="channel">
@ -27,19 +32,20 @@
</select> </select>
</div> </div>
<div> <div data-channel-only="telegram"{% if hide_telegram %} style="display:none"{% endif %}>
<label class="block text-xs uppercase text-slate-500 mb-1">Telegram Bot-Token</label> <label class="block text-xs uppercase text-slate-500 mb-1">Telegram Bot-Token</label>
<input class="input" name="telegram_bot_token" value="{{ notifications.telegram_bot_token }}" <input class="input" name="telegram_bot_token" value="{{ notifications.telegram_bot_token }}"
placeholder="123456:ABC..." autocomplete="off" data-lpignore="true" data-1p-ignore data-bwignore> placeholder="123456:ABC..." autocomplete="off" data-lpignore="true" data-1p-ignore data-bwignore>
<p class="text-xs text-slate-500 mt-1">Bot bei @BotFather anlegen, Token hier eintragen.</p> <p class="text-xs text-slate-500 mt-1">Bot bei @BotFather anlegen, Token hier eintragen.</p>
</div> </div>
<div> <div data-channel-only="telegram"{% if hide_telegram %} style="display:none"{% endif %}>
<label class="block text-xs uppercase text-slate-500 mb-1">Telegram Chat-ID</label> <label class="block text-xs uppercase text-slate-500 mb-1">Telegram Chat-ID</label>
<input class="input" name="telegram_chat_id" value="{{ notifications.telegram_chat_id }}" <input class="input" name="telegram_chat_id" value="{{ notifications.telegram_chat_id }}"
placeholder="987654321" autocomplete="off" data-lpignore="true" data-1p-ignore data-bwignore> placeholder="987654321" autocomplete="off" data-lpignore="true" data-1p-ignore data-bwignore>
</div> </div>
<div class="border-t border-soft pt-4 space-y-2"> <div class="border-t border-soft pt-4 space-y-2"
data-channel-only="telegram"{% if hide_telegram %} style="display:none"{% endif %}>
<label class="flex items-center gap-2"> <label class="flex items-center gap-2">
<input type="checkbox" name="notify_on_match" {% if notifications.notify_on_match %}checked{% endif %}> <input type="checkbox" name="notify_on_match" {% if notifications.notify_on_match %}checked{% endif %}>
<span>Bei passender Wohnung</span> <span>Bei passender Wohnung</span>
@ -57,6 +63,7 @@
<div class="flex gap-2"> <div class="flex gap-2">
<button class="btn btn-primary" type="submit">Speichern</button> <button class="btn btn-primary" type="submit">Speichern</button>
<button class="btn btn-ghost" type="submit" <button class="btn btn-ghost" type="submit"
formaction="/actions/notifications/test" formnovalidate>Test senden</button> formaction="/actions/notifications/test" formnovalidate
data-channel-only="telegram"{% if hide_telegram %} style="display:none"{% endif %}>Test senden</button>
</div> </div>
</form> </form>