From e9bceaab62c212c63d8be6ed0c520d0b0b217d82 Mon Sep 17 00:00:00 2001 From: Disco DeDisco Date: Fri, 8 May 2026 14:34:41 -0400 Subject: [PATCH] =?UTF-8?q?sky=20wheel:=20ubiquitous=20DEL=20btn=20?= =?UTF-8?q?=E2=80=94=20applet=20&=20PICK=20SKY=20parity=20w.=20Dashsky;=20?= =?UTF-8?q?PICK=20SKY=20clears=20client-only=20state=20(no=20User-model=20?= =?UTF-8?q?touch)=20=E2=80=94=20TDD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My Sky applet (.../dashboard/_partials/_applet-my-sky.html): adds {{ request.user.sky_chart_data|json_script:"id_my_sky_data" }} {% endif %} @@ -98,6 +101,38 @@ SkyWheel.preload().then(function () { SkyWheel.draw(svgEl, stale); }); }); + // DEL btn — guard portal → POST sky_delete + clear LS + reload. Reload is + // the simplest swap back to the form rendering (the form-rendering branch + // is server-template-gated on user.sky_chart_data). window.showGuard is + // assigned by the script in base.html that lives BELOW the content block, + // so the readiness check is deferred to click-time rather than gating the + // listener bind itself. + var delBtn = document.getElementById('id_applet_sky_delete_btn'); + if (delBtn) { + var DELETE_URL = delBtn.dataset.deleteUrl; + function _csrf() { + var m = document.cookie.match(/csrftoken=([^;]+)/); + return m ? m[1] : ''; + } + delBtn.addEventListener('click', function () { + if (!window.showGuard) return; + window.showGuard(delBtn, 'Forget sky?', function () { + fetch(DELETE_URL, { + method: 'POST', + credentials: 'same-origin', + headers: { 'X-CSRFToken': _csrf() }, + }).then(function (r) { + if (!r.ok) return; + // The form-render branch's _restoreForm() will re-seed + // fields from this LS entry on the next render — clear it + // so the post-reload form lands genuinely empty. + try { localStorage.removeItem('sky-form:dashboard:sky'); } catch (_) {} + window.location.reload(); + }); + }); + }); + } + {% else %} // No sky saved yet — wire up the entry form. diff --git a/src/templates/apps/gameboard/_partials/_sky_overlay.html b/src/templates/apps/gameboard/_partials/_sky_overlay.html index 204f3ed..1cea2bb 100644 --- a/src/templates/apps/gameboard/_partials/_sky_overlay.html +++ b/src/templates/apps/gameboard/_partials/_sky_overlay.html @@ -89,6 +89,8 @@ {# ── Wheel column ─────────────────────────────────────── #}
+
{# /.sky-modal-body #} @@ -399,6 +401,34 @@ window.location.reload(); } + // ── DEL btn — clears wheel + form + localStorage (no server hit) ──────── + // PICK SKY's wheel is a live preview; un-saved data lives only in LS_KEY. + // Match the My Sky applet / Dashsky pattern but skip the server delete — + // there's no Character draft created during preview (sky_save fires only + // on SAVE SKY click w. action='confirm'). + + // window.showGuard is assigned in a base.html script that loads BELOW the + // content block — defer the readiness check to click-time so the listener + // bind happens regardless of inline-script execution order. + const delBtn = document.getElementById('id_sky_delete_btn'); + if (delBtn) { + delBtn.addEventListener('click', () => { + if (!window.showGuard) return; + window.showGuard(delBtn, 'Forget sky?', () => { + while (svgEl.firstChild) svgEl.removeChild(svgEl.firstChild); + form.reset(); + latInput.value = ''; + lonInput.value = ''; + tzInput.value = ''; + tzHint.textContent = ''; + _lastChartData = null; + confirmBtn.disabled = true; + setStatus(''); + try { localStorage.removeItem(LS_KEY); } catch (_) {} + }); + }); + } + // ── CSRF ────────────────────────────────────────────────────────────────── function _getCsrf() {