Added remove button to print batch view

This commit is contained in:
2025-10-31 08:26:51 +01:00
parent 9a2de52c1f
commit 51bdd700cc

View File

@@ -100,9 +100,17 @@
downButton.setAttribute('data-batchId', i);
downButton.className = 'btn btn-sm btn-primary';
downButton.textContent = '↓';
let removeButton = document.createElement('button');
removeButton.setAttribute('data-action', 'remove');
removeButton.setAttribute('data-batchId', i);
removeButton.className = 'btn btn-sm btn-danger';
removeButton.innerHTML = 'X';
container.appendChild(upButton);
container.appendChild(document.createElement('br'));
container.appendChild(downButton);
container.appendChild(document.createElement('br'));
container.appendChild(removeButton);
upButton.addEventListener('click', function() {
moveCardInBatch(upButton.parentElement.parentElement.parentElement.parentElement.attributes["data-card-index"].value, "up");
});
@@ -110,6 +118,24 @@
downButton.addEventListener('click', function() {
moveCardInBatch(downButton.parentElement.parentElement.parentElement.parentElement.attributes["data-card-index"].value, "down");
});
removeButton.addEventListener('click', async function() {
const index = parseInt(removeButton.closest('[data-card-index]').getAttribute('data-card-index'));
let batch = getAssetIdsFromBatch();
if (batch && batch.length > index) {
batch.splice(index, 1);
localStorage.setItem("printBatch", JSON.stringify(batch));
}
await renderBarcodePreview("printPreviewContainer");
removeButton.closest('.card').remove();
document.querySelectorAll('#printModal .card').forEach((card, newIndex) => {
card.setAttribute('data-card-index', newIndex);
const title = card.querySelector('.card-title strong');
if (title) title.textContent = `Asset ${newIndex + 1}:`;
});
});
} catch (error) {
console.error(`Error fetching asset ${assetId}:`, error);
const errorDiv = document.createElement('div');