ui: fix propose modal script + category injection

This commit is contained in:
s-FunIA
2026-01-18 21:02:31 +01:00
parent 0c764cd9ab
commit e0a7b26f53

View File

@@ -35,8 +35,6 @@
.grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap:.5rem; }
.grid button { padding: .75rem .8rem; border-radius: 12px; border: 1px solid rgba(0,0,0,.18); background: rgba(255,255,255,.96); color: #111; cursor: pointer; text-align: left; }
.grid button:hover { background: #fff; }
.grid button:hover { background: #fff; }
.ft { margin-top:.75rem; opacity:.85; }
kbd { padding:0 .35rem; border:1px solid rgba(0,0,0,.2); border-radius:6px; }
</style>
@@ -50,41 +48,47 @@
const upsertLine = (text, key, value) => {
const re = new RegExp(`^${key}:\\s*.*$`, "mi");
if (!value) return text; // "continuer sans préciser"
// Si "continuer sans préciser" : on ne touche pas au body
if (!value) return text;
if (re.test(text)) return text.replace(re, `${key}: ${value}`);
const sep = text && !text.endsWith("\n") ? "\n" : "";
return text + sep + `${key}: ${value}\n`;
};
const openWith = (url) => {
const openModalFor = (url) => {
pending = url;
if (typeof dlg.showModal === "function") dlg.showModal();
else window.location.href = url.toString(); // fallback robuste
else window.open(url.toString(), "_blank", "noopener,noreferrer");
};
// Intercepte UNIQUEMENT les liens marqués data-propose
// Interception des clics sur "Proposer"
document.addEventListener("click", (e) => {
const a = e.target?.closest?.("a[data-propose]");
if (!a) return;
e.preventDefault();
// URL réelle stockée par EditionLayout (propose.dataset.url)
const rawUrl = a.dataset.url || a.getAttribute("href") || "";
if (!rawUrl || rawUrl === "#") return;
try {
openWith(new URL(a.href, window.location.origin));
openModalFor(new URL(rawUrl, window.location.origin));
} catch {
window.location.href = a.href;
window.open(rawUrl, "_blank", "noopener,noreferrer");
}
});
// Choix dune catégorie -> injection "Category:" + ouverture Gitea
dlg.addEventListener("click", (e) => {
const btn = e.target?.closest?.("button[data-category]");
if (!btn || !pending) return;
const cat = btn.getAttribute("data-category") || "";
let body = pending.searchParams.get("body") || "";
body = upsertLine(body, "Category", cat); // clé stable (sans accents)
const body = pending.searchParams.get("body") || "";
pending.searchParams.set("body", upsertLine(body, "Category", cat));
pending.searchParams.set("body", body);
dlg.close();
window.open(pending.toString(), "_blank", "noopener,noreferrer");
});
})();