From 09d9befceb40776231fbbbdea76beea4caa52cca Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 1 Nov 2025 21:20:10 +0000 Subject: [PATCH] Implement row selection controls in templates and refactor related JavaScript functionality --- atlas/tables.py | 2 +- atlas/templates/atlas/case_view.html | 1 + generic/tables.py | 30 ++++ templates/base.html | 217 +++++++++++++++------------ templates/question_table_view.html | 13 +- 5 files changed, 150 insertions(+), 113 deletions(-) diff --git a/atlas/tables.py b/atlas/tables.py index f516b9ff..d5d2f511 100755 --- a/atlas/tables.py +++ b/atlas/tables.py @@ -174,7 +174,7 @@ class CaseTable(SelectionTable): "atlas:case_delete", text="Delete", args=[A("pk")], orderable=False ) - selection = tables.CheckBoxColumn(accessor="pk", orderable=False) + #selection = tables.CheckBoxColumn(accessor="pk", orderable=False) class Meta: model = Case diff --git a/atlas/templates/atlas/case_view.html b/atlas/templates/atlas/case_view.html index 0666e2c0..a07a91f6 100755 --- a/atlas/templates/atlas/case_view.html +++ b/atlas/templates/atlas/case_view.html @@ -77,6 +77,7 @@ + {{ table.row_selection_controls|safe }} {% render_table table %} diff --git a/generic/tables.py b/generic/tables.py index c20bd3e9..83c2cadd 100644 --- a/generic/tables.py +++ b/generic/tables.py @@ -57,6 +57,36 @@ class SelectionTable(tables.Table): # Defensive: don't break table rendering if introspection fails pass + @property + def row_selection_controls(self): + """Return HTML for the row-selection control bar. + + Usage: render in template with `{{ table.row_selection_controls|safe }}` + + The control IDs are suffixed with a small per-instance token to + avoid collisions when multiple tables are present on the same page. + """ + token = format(id(self), 'x') + + html = ( + "
" + "
" + " " + "
" + " " + " " + "
" + "
" + "
" + " Selected: 0" + "
" + "
" + ).format(token, token, token, token, token) + + # Also include a small data attribute so client scripts can locate the + # controls by selection name if they prefer. + return format_html(html) + class SingleImageColumn(tables.Column): def render(self, value): try: diff --git a/templates/base.html b/templates/base.html index 225b15ba..b373a6d9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -312,113 +312,130 @@ diff --git a/templates/question_table_view.html b/templates/question_table_view.html index c0bf92cb..9478e568 100644 --- a/templates/question_table_view.html +++ b/templates/question_table_view.html @@ -29,19 +29,8 @@
-
-
- - -
-
- Selected: 0 -
-
+ {{ table.row_selection_controls|safe }}
{% render_table table %}