fix: enabled toggle — list-row click + edit-form save
Two bugs in the channel-enabled affordance:
1. List-row toggle was a static span with no handler; the row's
row-link overlay swallowed every click and routed to /edit. Add
POST /settings/notifications/{id}/toggle backed by a new store
method SetNotificationChannelEnabled, and turn the row toggle
into an htmx-driven button that swaps in the new state. Use
event.stopPropagation() on the toggle so it beats the row link.
2. Edit-form toggle visually flipped but the underlying checkbox
reverted: the visual span lives inside the <label>, so clicking
it fired the inline JS handler AND the label's native
checkbox-toggle, cancelling out. Bind to the checkbox 'change'
event instead and let the label do the toggling — the JS just
mirrors check.checked into the .on class.
This commit is contained in:
@@ -99,8 +99,18 @@
|
||||
<div class="mono text-ink-mute" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
|
||||
{{if eq $ch.Kind "webhook"}}webhook · click to edit{{else if eq $ch.Kind "ntfy"}}ntfy · click to edit{{else}}smtp · click to edit{{end}}
|
||||
</div>
|
||||
<div>
|
||||
{{if $ch.Enabled}}<span class="toggle on"></span>{{else}}<span class="toggle"></span>{{end}}
|
||||
<div class="row-action">
|
||||
{{if $ch.Enabled}}
|
||||
<span class="toggle on" hx-post="/settings/notifications/{{$ch.ID}}/toggle"
|
||||
hx-target="this" hx-swap="outerHTML"
|
||||
onclick="event.stopPropagation()" style="cursor:pointer"
|
||||
title="click to disable"></span>
|
||||
{{else}}
|
||||
<span class="toggle" hx-post="/settings/notifications/{{$ch.ID}}/toggle"
|
||||
hx-target="this" hx-swap="outerHTML"
|
||||
onclick="event.stopPropagation()" style="cursor:pointer"
|
||||
title="click to enable"></span>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="mono text-ink-mid">
|
||||
{{if $ch.LastFiredAt}}{{relTime $ch.LastFiredAt}}{{else}}<span class="text-ink-fade">never</span>{{end}}
|
||||
@@ -521,12 +531,16 @@ https://restic-manager.example/alerts/01KQTABCDEFGHJ</pre>
|
||||
});
|
||||
});
|
||||
|
||||
// Enabled toggle
|
||||
// Enabled toggle: the visual <span class="toggle"> is inside a <label>
|
||||
// wrapping a hidden checkbox, so clicking the span already flips the
|
||||
// checkbox via the label's native behaviour. We only need to mirror
|
||||
// that into the .on class — listening on the toggle's own click would
|
||||
// race the label and cancel out, leaving check.checked at its original
|
||||
// value (so Save would persist the unchanged setting).
|
||||
var check = document.getElementById('enabled-check');
|
||||
var tog = document.getElementById('enabled-toggle');
|
||||
if (check && tog) {
|
||||
tog.addEventListener('click', function() {
|
||||
check.checked = !check.checked;
|
||||
check.addEventListener('change', function() {
|
||||
tog.classList.toggle('on', check.checked);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user