fix: synchronize table row state with selection logic and update export flow to default to all items when none are selected
This commit is contained in:
parent
f34e26f8f5
commit
107575aa60
1 changed files with 38 additions and 12 deletions
|
|
@ -725,10 +725,10 @@ $(document).ready(function () {
|
||||||
ignoreClickToSelectOn: function (element) {
|
ignoreClickToSelectOn: function (element) {
|
||||||
return $(element).closest('.zoom-btn, .unified-code-link').length > 0;
|
return $(element).closest('.zoom-btn, .unified-code-link').length > 0;
|
||||||
},
|
},
|
||||||
onCheck: function (row) { selectedIds.add(row.id); updateSelectionStatus(); },
|
onCheck: function (row) { row.state = true; selectedIds.add(row.id); updateSelectionStatus(); },
|
||||||
onUncheck: function (row) { selectedIds.delete(row.id); updateSelectionStatus(); },
|
onUncheck: function (row) { row.state = false; selectedIds.delete(row.id); updateSelectionStatus(); },
|
||||||
onCheckAll: function (rows) { rows.forEach(r => selectedIds.add(r.id)); updateSelectionStatus(); },
|
onCheckAll: function (rows) { rows.forEach(r => { r.state = true; selectedIds.add(r.id); }); updateSelectionStatus(); },
|
||||||
onUncheckAll: function (rows) { rows.forEach(r => selectedIds.delete(r.id)); updateSelectionStatus(); },
|
onUncheckAll: function (rows) { rows.forEach(r => { r.state = false; selectedIds.delete(r.id); }); updateSelectionStatus(); },
|
||||||
onClickRow: function (row) {
|
onClickRow: function (row) {
|
||||||
if (!row.lon || !row.lat) return;
|
if (!row.lon || !row.lat) return;
|
||||||
const source = row.is_location ? 'locations' : 'assets';
|
const source = row.is_location ? 'locations' : 'assets';
|
||||||
|
|
@ -1126,14 +1126,28 @@ $(document).ready(function () {
|
||||||
|
|
||||||
// ─── Select all / deselect all ─────────────────────────────────────────
|
// ─── 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');
|
$('#unified-table').bootstrapTable('checkAll');
|
||||||
});
|
|
||||||
document.getElementById('unified-deselect-all').addEventListener('click', function () {
|
|
||||||
$('#unified-table').bootstrapTable('uncheckAll');
|
|
||||||
selectedIds.clear();
|
|
||||||
updateSelectionStatus();
|
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();
|
bindUnifiedAssetsExport();
|
||||||
bindUnifiedBulkActions();
|
bindUnifiedBulkActions();
|
||||||
|
|
@ -1435,12 +1449,13 @@ function getCsrfToken() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedAssetKeysForExport() {
|
function getSelectedAssetKeysForExport() {
|
||||||
const rows = $('#unified-table').bootstrapTable('getSelections') || [];
|
const rows = $('#unified-table').bootstrapTable('getData') || [];
|
||||||
const keys = [];
|
const keys = [];
|
||||||
const seen = new Set();
|
const seen = new Set();
|
||||||
|
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
if (!row || row.is_location) return;
|
if (!row || row.is_location) return;
|
||||||
|
if (selectedIds.size > 0 && !selectedIds.has(row.id)) return;
|
||||||
|
|
||||||
const modelName = String(row.asset_type || '').toLowerCase().trim();
|
const modelName = String(row.asset_type || '').toLowerCase().trim();
|
||||||
const objectId = Number(row.id);
|
const objectId = Number(row.id);
|
||||||
|
|
@ -1465,10 +1480,20 @@ function bindUnifiedAssetsExport() {
|
||||||
if (!exportError) return;
|
if (!exportError) return;
|
||||||
exportError.classList.add('d-none');
|
exportError.classList.add('d-none');
|
||||||
exportError.textContent = '';
|
exportError.textContent = '';
|
||||||
|
|
||||||
|
const currentSelectedKeys = getSelectedAssetKeysForExport();
|
||||||
|
if (!currentSelectedKeys.length) {
|
||||||
|
selectAllTableRows();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
exportConfirmBtn.addEventListener('click', function () {
|
exportConfirmBtn.addEventListener('click', function () {
|
||||||
const ids = getSelectedAssetKeysForExport();
|
let ids = getSelectedAssetKeysForExport();
|
||||||
|
if (!ids.length) {
|
||||||
|
selectAllTableRows();
|
||||||
|
ids = getSelectedAssetKeysForExport();
|
||||||
|
}
|
||||||
|
|
||||||
if (!ids.length) {
|
if (!ids.length) {
|
||||||
if (exportError) {
|
if (exportError) {
|
||||||
exportError.textContent = gettext('Veuillez sélectionner au moins un asset.');
|
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);
|
const area = Number(p.area ?? p.area_m2 ?? p.surface_area ?? p.surface ?? 0);
|
||||||
return {
|
return {
|
||||||
id: f.id,
|
id: f.id,
|
||||||
|
state: selectedIds.has(f.id),
|
||||||
code: p.code || '',
|
code: p.code || '',
|
||||||
name: name,
|
name: name,
|
||||||
asset_type: p.asset_type || '',
|
asset_type: p.asset_type || '',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue