Refactor table row selection logic and remove associated CSS styles for improved clarity and maintainability

This commit is contained in:
Ross
2025-11-01 21:04:01 +00:00
parent cbf4c3497d
commit 62c26d199e
3 changed files with 3 additions and 47 deletions
-31
View File
@@ -176,37 +176,6 @@ $(document).ready(function () {
});
// Table row selection
// Delegate click event to all table rows
document.querySelectorAll('.row-selector tbody tr').forEach(function(row) {
row.addEventListener('click', function(e) {
// Ignore clicks on links or checkboxes
if (e.target.tagName === 'A' || e.target.tagName === 'INPUT') return;
// Find the checkbox in this row
const checkbox = row.querySelector('input[name="selection"]');
if (checkbox) {
checkbox.checked = !checkbox.checked;
row.classList.toggle('selected', checkbox.checked);
}
});
// Keep row visually in sync with checkbox state (e.g. after page reload)
const checkbox = row.querySelector('input[name="selection"]');
if (checkbox && checkbox.checked) {
row.classList.add('selected');
}
// Also toggle row selection when checkbox is clicked directly
if (checkbox) {
checkbox.addEventListener('click', function(e) {
row.classList.toggle('selected', checkbox.checked);
// Prevent row click event from firing
e.stopPropagation();
});
}
});
});
window.loadDicomViewerEvent = new Event('loadDicomViewer');
+3 -3
View File
@@ -1,7 +1,7 @@
import django_tables2 as tables
from django_tables2.utils import A
from generic.tables import SeriesImageColumn
from generic.tables import SeriesImageColumn, SelectionTable
from .models import (
Case,
@@ -25,7 +25,7 @@ from easy_thumbnails.exceptions import InvalidImageFormatError
from django.db.models import Prefetch
class CaseTable(tables.Table):
class CaseTable(SelectionTable):
def __init__(self, data=None, *args, **kwargs):
# Optimize prefetching for casecollection_set
#case_collections_prefetch = Prefetch(
@@ -190,7 +190,7 @@ class CaseTable(tables.Table):
)
sequence = ("view", )
order_by = "-created_date"
attrs = {"class": "table row-selector"}
attrs = {"class": "table"}
-13
View File
@@ -1397,19 +1397,6 @@ span#user-id {
opacity: 1;
}
/* Highlight row on hover */
.row-selector tbody tr:hover td {
background-color: darkblue;
cursor: pointer;
}
/* Highlight selected row */
.row-selector tbody tr.selected td {
background-color: #b3d7ff !important;
color: #333;
}
.image-block {
min-width: 100px;
display: inline-block;