From 107575aa60c1da337484a44c571430d376a7edd3 Mon Sep 17 00:00:00 2001 From: kdeterme Date: Mon, 10 Aug 2026 22:47:18 +0200 Subject: [PATCH] fix: synchronize table row state with selection logic and update export flow to default to all items when none are selected --- .../assets/static/assets/unified_index.js | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/streetup/assets/static/assets/unified_index.js b/streetup/assets/static/assets/unified_index.js index 1fd0971..1686c66 100644 --- a/streetup/assets/static/assets/unified_index.js +++ b/streetup/assets/static/assets/unified_index.js @@ -725,10 +725,10 @@ $(document).ready(function () { ignoreClickToSelectOn: function (element) { return $(element).closest('.zoom-btn, .unified-code-link').length > 0; }, - onCheck: function (row) { selectedIds.add(row.id); updateSelectionStatus(); }, - onUncheck: function (row) { selectedIds.delete(row.id); updateSelectionStatus(); }, - onCheckAll: function (rows) { rows.forEach(r => selectedIds.add(r.id)); updateSelectionStatus(); }, - onUncheckAll: function (rows) { rows.forEach(r => selectedIds.delete(r.id)); updateSelectionStatus(); }, + onCheck: function (row) { row.state = true; selectedIds.add(row.id); updateSelectionStatus(); }, + onUncheck: function (row) { row.state = false; selectedIds.delete(row.id); updateSelectionStatus(); }, + onCheckAll: function (rows) { rows.forEach(r => { r.state = true; selectedIds.add(r.id); }); updateSelectionStatus(); }, + onUncheckAll: function (rows) { rows.forEach(r => { r.state = false; selectedIds.delete(r.id); }); updateSelectionStatus(); }, onClickRow: function (row) { if (!row.lon || !row.lat) return; const source = row.is_location ? 'locations' : 'assets'; @@ -1126,14 +1126,28 @@ $(document).ready(function () { // ─── Select all / deselect all ───────────────────────────────────────── - document.getElementById('unified-select-all').addEventListener('click', function () { + function selectAllTableRows() { + const allRows = $('#unified-table').bootstrapTable('getData') || []; + allRows.forEach(r => { + selectedIds.add(r.id); + r.state = true; + }); $('#unified-table').bootstrapTable('checkAll'); - }); - document.getElementById('unified-deselect-all').addEventListener('click', function () { - $('#unified-table').bootstrapTable('uncheckAll'); - selectedIds.clear(); updateSelectionStatus(); - }); + } + + function deselectAllTableRows() { + const allRows = $('#unified-table').bootstrapTable('getData') || []; + allRows.forEach(r => { + r.state = false; + }); + selectedIds.clear(); + $('#unified-table').bootstrapTable('uncheckAll'); + updateSelectionStatus(); + } + + document.getElementById('unified-select-all').addEventListener('click', selectAllTableRows); + document.getElementById('unified-deselect-all').addEventListener('click', deselectAllTableRows); bindUnifiedAssetsExport(); bindUnifiedBulkActions(); @@ -1435,12 +1449,13 @@ function getCsrfToken() { } function getSelectedAssetKeysForExport() { - const rows = $('#unified-table').bootstrapTable('getSelections') || []; + const rows = $('#unified-table').bootstrapTable('getData') || []; const keys = []; const seen = new Set(); rows.forEach(row => { if (!row || row.is_location) return; + if (selectedIds.size > 0 && !selectedIds.has(row.id)) return; const modelName = String(row.asset_type || '').toLowerCase().trim(); const objectId = Number(row.id); @@ -1465,10 +1480,20 @@ function bindUnifiedAssetsExport() { if (!exportError) return; exportError.classList.add('d-none'); exportError.textContent = ''; + + const currentSelectedKeys = getSelectedAssetKeysForExport(); + if (!currentSelectedKeys.length) { + selectAllTableRows(); + } }); exportConfirmBtn.addEventListener('click', function () { - const ids = getSelectedAssetKeysForExport(); + let ids = getSelectedAssetKeysForExport(); + if (!ids.length) { + selectAllTableRows(); + ids = getSelectedAssetKeysForExport(); + } + if (!ids.length) { if (exportError) { exportError.textContent = gettext('Veuillez sélectionner au moins un asset.'); @@ -2343,6 +2368,7 @@ function loadTableData(features) { const area = Number(p.area ?? p.area_m2 ?? p.surface_area ?? p.surface ?? 0); return { id: f.id, + state: selectedIds.has(f.id), code: p.code || '', name: name, asset_type: p.asset_type || '',