Moved csv edit js to a separate file
This commit is contained in:
parent
f34ec454bf
commit
bfd4ecfd7a
@ -10,7 +10,6 @@ def confirm_save():
|
||||
edited_assets = json.loads(request.form['assets'])
|
||||
session['assets'] = edited_assets
|
||||
|
||||
#assets = session.get('assets', []) # Retrieve assets from session
|
||||
for asset_data in edited_assets:
|
||||
asset = Asset(
|
||||
assettag=asset_data['assettag'],
|
||||
|
22
static/edited _csv.js
Normal file
22
static/edited _csv.js
Normal file
@ -0,0 +1,22 @@
|
||||
function collectEditedData() {
|
||||
const rows = document.querySelectorAll('tbody tr');
|
||||
const assets = [];
|
||||
|
||||
rows.forEach(row => {
|
||||
const cells = row.querySelectorAll('td');
|
||||
assets.push({
|
||||
assettag: cells[0].innerText,
|
||||
hostname: cells[1].innerText,
|
||||
warrantyfrom: cells[2].innerText,
|
||||
status: cells[3].innerText,
|
||||
staffnum: cells[4].innerText
|
||||
});
|
||||
});
|
||||
|
||||
// Add edited data to a hidden input
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = 'assets';
|
||||
input.value = JSON.stringify(assets);
|
||||
document.querySelector('form').appendChild(input);
|
||||
}
|
@ -4,30 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CSV Preview</title>
|
||||
<script>
|
||||
function collectEditedData() {
|
||||
const rows = document.querySelectorAll('tbody tr');
|
||||
const assets = [];
|
||||
|
||||
rows.forEach(row => {
|
||||
const cells = row.querySelectorAll('td');
|
||||
assets.push({
|
||||
assettag: cells[0].innerText,
|
||||
hostname: cells[1].innerText,
|
||||
warrantyfrom: cells[2].innerText,
|
||||
status: cells[3].innerText,
|
||||
staffnum: cells[4].innerText
|
||||
});
|
||||
});
|
||||
|
||||
// Add edited data to a hidden input
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = 'assets';
|
||||
input.value = JSON.stringify(assets);
|
||||
document.querySelector('form').appendChild(input);
|
||||
}
|
||||
</script>
|
||||
<script src="{{ url_for('static', filename='edited _csv.js') }}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CSV Preview</h1>
|
||||
|
Loading…
Reference in New Issue
Block a user