From f260e8a605e53c782ad128e31a31679ed7fcba66 Mon Sep 17 00:00:00 2001 From: bach Date: Fri, 4 Sep 2026 21:57:33 +0200 Subject: [PATCH] Inline-edit the type badge directly in the table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking a row's type badge swaps it for a native in place + (figli-type-select below), no modal needed for this one field. */ +#figli-home-app .figli-badge-editable { + cursor: pointer; + border: 1px solid transparent; +} +#figli-home-app .figli-badge-editable:hover { + border-color: currentColor; +} +#figli-home-app .figli-type-select { + font-size: 0.72rem; + padding: 0.05rem 0.2rem; + background: var(--figli-bg); + color: var(--figli-text); + border: 1px solid var(--figli-border); + border-radius: 4px; +} + #figli-home-app .figli-note { color: var(--figli-text-light); font-weight: 400; @@ -315,3 +333,14 @@ html.gin--dark-mode #figli-home-app { padding: 0.75rem 1rem; border-radius: 6px; } + +/* Dismissible, doesn't replace the table like the top-level fetch error + does -- a failed inline type change is a small hiccup, not a reason to + hide everything that's already loaded. */ +#figli-home-app .figli-inline-error { + margin-bottom: 1rem; + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.75rem; +} diff --git a/web/modules/custom/figli_compta_ledger/figli_compta_ledger.routing.yml b/web/modules/custom/figli_compta_ledger/figli_compta_ledger.routing.yml index 30de5eb..cd5e0dd 100644 --- a/web/modules/custom/figli_compta_ledger/figli_compta_ledger.routing.yml +++ b/web/modules/custom/figli_compta_ledger/figli_compta_ledger.routing.yml @@ -54,3 +54,15 @@ figli_compta_ledger.api_reconciliation_ouverture: _controller: '\Drupal\figli_compta_ledger\Controller\LedgerStatsController::reconciliationOuverture' requirements: _permission: 'access content' + +figli_compta_ledger.update_type: + path: '/lignes/{node}/type' + defaults: + _controller: '\Drupal\figli_compta_ledger\Controller\LedgerActionsController::updateType' + methods: [POST] + requirements: + _entity_access: 'node.update' + options: + parameters: + node: + type: entity:node diff --git a/web/modules/custom/figli_compta_ledger/js/home.js b/web/modules/custom/figli_compta_ledger/js/home.js index c635cbc..aa6cd20 100644 --- a/web/modules/custom/figli_compta_ledger/js/home.js +++ b/web/modules/custom/figli_compta_ledger/js/home.js @@ -129,6 +129,23 @@ return res.json(); } + // POST /lignes/{nid}/type -- change field_type_ligne without opening the + // full edit form. Fetches a fresh CSRF token each time (core's + // /session/token) rather than caching one -- this is an occasional + // action, not worth the complexity of handling a stale cached token. + async function updateLigneType(nid, type) { + const tokenRes = await fetch('/session/token'); + const token = await tokenRes.text(); + const res = await fetch('/lignes/' + nid + '/type', { + method: 'POST', + headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': token }, + body: JSON.stringify({ type }), + }); + const json = await res.json().catch(() => ({})); + if (!res.ok) throw new Error(json.error || ('/lignes/' + nid + '/type a répondu ' + res.status)); + return json; + } + async function fetchYearTotals(annee) { const res = await fetch('/lignes/api/totaux?annee=' + encodeURIComponent(annee), { headers: { Accept: 'application/json' } }); if (!res.ok) throw new Error('/lignes/api/totaux a répondu ' + res.status); @@ -202,6 +219,10 @@ onlyErrors: false, hoverCol: null, filterEntreeId: null, + // Which row's type badge is currently showing its inline + + + {{ typeLabel(item.type) }} + {{ item.libelle }}