Adjusted csv upload javascript to use the config
This commit is contained in:
parent
ef951cbb91
commit
3762534c65
@ -1,25 +1,21 @@
|
|||||||
function collectEditedData(event) {
|
function collectEditedData(event) {
|
||||||
|
const headers = [...document.querySelectorAll('.table-new-assets thead th')].map(th => th.dataset.attrib);
|
||||||
const rows = document.querySelectorAll('.table-new-assets tbody tr');
|
const rows = document.querySelectorAll('.table-new-assets tbody tr');
|
||||||
const assets = [];
|
const assets = [];
|
||||||
|
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
const cells = row.querySelectorAll('td');
|
const cells = row.querySelectorAll('td');
|
||||||
assets.push({
|
let asset = {};
|
||||||
assettag: cells[0].innerText,
|
headers.forEach((attrib, i) => asset[attrib] = cells[i].innerText);
|
||||||
hostname: cells[1].innerText,
|
assets.push(asset);
|
||||||
warrantyfrom: cells[2].innerText,
|
|
||||||
status: cells[3].innerText,
|
|
||||||
staffnum: cells[4].innerText
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add edited data to a hidden input
|
|
||||||
const input = document.createElement('input');
|
const input = document.createElement('input');
|
||||||
input.type = 'hidden';
|
input.type = 'hidden';
|
||||||
input.name = 'assets';
|
input.name = 'assets';
|
||||||
input.value = JSON.stringify(assets);
|
input.value = JSON.stringify(assets);
|
||||||
document.querySelector('form').appendChild(input);
|
document.querySelector('form').appendChild(input);
|
||||||
|
|
||||||
event.target.submit(); // Submit the form after attaching data
|
event.target.submit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -16,7 +16,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{% for attrib, config in item_attributes.items() %}
|
{% for attrib, config in item_attributes.items() %}
|
||||||
<th>{{ config.display_name }}</th>
|
<th data-attrib="{{ attrib }}">{{ config.display_name }}</th>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
Loading…
Reference in New Issue
Block a user