assettrack/static/js/edited_csv.js
candifloss 8fa4841c53 fix: BrandingConfig, Move: js directory
- Fix template rendering without BrandingConfig in some pages
- Moved JS file to static/js/ subdirectory
2025-04-03 12:14:16 +05:30

40 lines
1.3 KiB
JavaScript

function collectEditedData(event) {
// Prevent default form submission
event.preventDefault();
// Extract headers (attribute names) from the table
const headers = [...document.querySelectorAll('.table-valid-entries thead th')].map(th => th.dataset.attrib);
const rows = document.querySelectorAll('.table-valid-entries tbody tr');
const assets = [];
// Iterate through rows and collect data
rows.forEach(row => {
const cells = row.querySelectorAll('td');
if (cells.length !== headers.length) {
alert("Mismatch between the number of cells and headers. Please check the table.");
return false;
}
let asset = {};
headers.forEach((attrib, i) => {
if (cells[i]) {
asset[attrib] = cells[i].innerText.trim();
} else {
alert(`Missing data for attribute: ${attrib}`);
return false;
}
});
assets.push(asset);
});
// Create a hidden input field to store the collected data
const input = document.createElement('input');
input.type = 'hidden';
input.name = 'assets';
input.value = JSON.stringify(assets);
event.currentTarget.appendChild(input);
// Submit the form
event.currentTarget.submit();
return true;
}