From 9760be8f27be7830a5f05180829d8bfcaa7acc54 Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 16 Nov 2025 23:03:19 +0000 Subject: [PATCH] Enhance case list item links and management actions: update hrefs for dynamic case numbering and improve button structure for better accessibility --- .../atlas/partials/case_list_item.html | 8 ++- .../casedetails_management_links.html | 13 ++++- templates/exam_overview_js.html | 57 ++++++++++++++++--- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/atlas/templates/atlas/partials/case_list_item.html b/atlas/templates/atlas/partials/case_list_item.html index 8f229296..d75b1aae 100644 --- a/atlas/templates/atlas/partials/case_list_item.html +++ b/atlas/templates/atlas/partials/case_list_item.html @@ -3,8 +3,12 @@
- {{ casedetail.case.title }} -
Case {{ forloop.counter }} — {{ casedetail.case.description|default_if_none:""|truncatechars:80 }}
+ + {{ casedetail.case.title }} + +
Case {{ forloop.counter }}{{ casedetail.case.description|default_if_none:""|truncatechars:80 }}
diff --git a/atlas/templates/atlas/partials/casedetails_management_links.html b/atlas/templates/atlas/partials/casedetails_management_links.html index 1653d155..57f71e10 100644 --- a/atlas/templates/atlas/partials/casedetails_management_links.html +++ b/atlas/templates/atlas/partials/casedetails_management_links.html @@ -1,4 +1,4 @@ - +
@@ -30,4 +30,13 @@ {% endif %} - \ No newline at end of file +
+ + {# Remove button (HTMX) - only shown when the surrounding template has `can_edit` true #} + {% if can_edit %} +
+ +
+ {% endif %} \ No newline at end of file diff --git a/templates/exam_overview_js.html b/templates/exam_overview_js.html index ad431ce2..2b6ba740 100644 --- a/templates/exam_overview_js.html +++ b/templates/exam_overview_js.html @@ -155,17 +155,38 @@ for (var i = ul.children.length; i >= 0; i--) { ul.appendChild(ul.children[Math.random() * i | 0]); } + renumber(); })) + // helper to renumber visible cases and update links + function renumber() { + $("#full-question-list li").each((i, e) => { + // update Case N label + $(e).find('.case-number').text('Case ' + (i + 1)); + + // update link href based on data-case-base-href (replace trailing 0) + const a = $(e).find('.case-link'); + if (a.length) { + const base = a.attr('data-case-base-href'); + if (base) { + // replace trailing '/0' with new index + const newHref = base.replace(/\/0$/, '/' + i); + a.attr('href', newHref); + } + } + }); + } + $("#full-question-list li").each((n, el) => { - // Add up/down arrows at the start of each
  • + // Add up/down arrows at the start of each
  • const upBtn = $("").click(function(e){ e.preventDefault(); const li = $(this).closest("li"); const prev = li.prev(); if (prev.length) { prev.before(li); + renumber(); } }); const downBtn = $("").click(function(e){ @@ -174,16 +195,23 @@ const next = li.next(); if (next.length) { next.after(li); + renumber(); } }); $(el).prepend(downBtn).prepend(upBtn); - // Existing delete button logic - $(el).append($( - "" - ).click(() => { - el.remove(); - })); + // Prefer server-side HTMX remove button when present; otherwise keep a fallback + if ($(el).find('.case-remove').length === 0) { + // fallback: append an inline client-side remove button (for contexts without server-side remove) + $(el).append($( + "" + ).click(() => { + el.remove(); + renumber(); + })); + } else { + // If HTMX remove exists it will handle the server call and swap; renumber after swap via htmx:afterSwap + } }); $("#full-question-list").after($( @@ -208,6 +236,7 @@ if (data.status == "success") { toastr.info('Exam order changed.') + renumber(); } }) .always(function () { @@ -220,6 +249,20 @@ ).click(() => { location.reload(); })); + // Keep list numbering in sync after HTMX swaps that affect the case list + document.body.addEventListener('htmx:afterSwap', function(evt){ + try { + const target = evt.detail && evt.detail.target ? evt.detail.target : null; + if (!target) return; + if (target.id === 'full-question-list' || (target.closest && target.closest('#full-question-list'))) { + setTimeout(function(){ + if (typeof renumber === 'function') renumber(); + }, 10); + } + } catch(e) { + console.error('htmx afterSwap renumber error', e); + } + }); });