diff --git a/atlas/templates/atlas/case_view.html b/atlas/templates/atlas/case_view.html index a07a91f6..0666e2c0 100755 --- a/atlas/templates/atlas/case_view.html +++ b/atlas/templates/atlas/case_view.html @@ -77,7 +77,6 @@ - {{ table.row_selection_controls|safe }} {% render_table table %} diff --git a/sbas/tables.py b/sbas/tables.py index d9b3f837..b2292332 100644 --- a/sbas/tables.py +++ b/sbas/tables.py @@ -55,7 +55,7 @@ class QuestionTable(SelectionTable): "edit" ) sequence = ("view", "stem", "answers")#, "exams") - attrs = {"class": "table"} + #`attrs = {"class": "table"} order_by = "-created_date" def __init__(self, data=None, *args, **kwargs): diff --git a/templates/base.html b/templates/base.html index b373a6d9..f1e788aa 100644 --- a/templates/base.html +++ b/templates/base.html @@ -316,24 +316,24 @@ document.addEventListener('DOMContentLoaded', function() { function findTableForControl(elem) { // Walk up ancestors and look for a table that either has the // `js-row-selectable` class or contains a checkbox named 'selection'. - var ancestor = elem.closest('div, section, main, article, form, body'); - while (ancestor) { - // Prefer explicit selectable class - var tbl = ancestor.querySelector && ancestor.querySelector('table.js-row-selectable'); - if (tbl) return tbl; - // Otherwise look for any table in this ancestor that contains a - // checkbox input named 'selection' (or any checkbox as a fallback). - var tables = ancestor.querySelectorAll && ancestor.querySelectorAll('table'); - if (tables && tables.length) { - for (var i = 0; i < tables.length; i++) { - var t = tables[i]; - if (t.querySelector && (t.querySelector('input[name="selection"]') || t.querySelector('input[type="checkbox"]'))) return t; - } - } - ancestor = ancestor.parentElement; - } + //var ancestor = elem.closest('div, section, main, article, form, body'); + //while (ancestor) { + // // Prefer explicit selectable class + // var tbl = ancestor.querySelector && ancestor.querySelector('table.js-row-selectable'); + // if (tbl) return tbl; + // // Otherwise look for any table in this ancestor that contains a + // // checkbox input named 'selection' (or any checkbox as a fallback). + // var tables = ancestor.querySelectorAll && ancestor.querySelectorAll('table'); + // if (tables && tables.length) { + // for (var i = 0; i < tables.length; i++) { + // var t = tables[i]; + // if (t.querySelector && (t.querySelector('input[name="selection"]') || t.querySelector('input[type="checkbox"]'))) return t; + // } + // } + // ancestor = ancestor.parentElement; + //} // fallback to any table on the page that looks like it has selection - var any = document.querySelector('table.js-row-selectable') || Array.from(document.querySelectorAll('table')).find(function(t){ return t.querySelector && (t.querySelector('input[name="selection"]') || t.querySelector('input[type="checkbox"]')); }); + var any = document.querySelector('table.js-row-selectable') //|| Array.from(document.querySelectorAll('table')).find(function(t){ return t.querySelector && (t.querySelector('input[name="selection"]') || t.querySelector('input[type="checkbox"]')); }); return any || null; } @@ -342,6 +342,45 @@ document.addEventListener('DOMContentLoaded', function() { return token ? idBase + '-' + token : idBase; } + // Ensure every selectable table has a row-selection control block. If the + // page author didn't render the controls, create them automatically and + // insert them before the table so the behavior is available out-of-the-box. + function ensureControlsForTable(table) { + if (!table) return; + // detect an existing nearby toggle button + var existing = table.previousElementSibling && table.previousElementSibling.querySelector && table.previousElementSibling.querySelector('[id^="toggle-row-selection"]'); + if (existing) return; // already present + + // generate a short token for unique IDs + var token = (Date.now().toString(16) + Math.floor(Math.random()*0xffff).toString(16)); + + var wrapper = document.createElement('div'); + wrapper.className = 'row-selection-controls-wrapper'; + wrapper.innerHTML = '
' + + '
' + + ' ' + + ' ' + + '
' + + '
' + + ' Selected: 0' + + '
' + + '
'; + + // Insert the controls immediately before the table (or its responsive wrapper) + var container = table.closest('.table-responsive') || table; + container.parentNode.insertBefore(wrapper, container); + } + + // Create controls for any table that looks selectable but lacks a control block + Array.from(document.querySelectorAll('table')).forEach(function(t){ + if (t.querySelector && (t.querySelector('input[name="selection"]') || t.querySelector('input[type="checkbox"]'))) { + ensureControlsForTable(t); + } + }); + // For every toggle button (supports both unsuffixed and suffixed IDs) document.querySelectorAll('button[id^="toggle-row-selection"]').forEach(function(toggleBtn) { // derive token (empty for unsuffixed) diff --git a/templates/question_table_view.html b/templates/question_table_view.html index 9478e568..b93c85cd 100644 --- a/templates/question_table_view.html +++ b/templates/question_table_view.html @@ -30,7 +30,6 @@
- {{ table.row_selection_controls|safe }}
{% render_table table %}