From bfd4ecfd7ab1060a049d64e437c81e145b2e5d2e Mon Sep 17 00:00:00 2001 From: candifloss Date: Wed, 5 Feb 2025 01:19:34 +0530 Subject: [PATCH] Moved csv edit js to a separate file --- routes/confirm_save.py | 1 - static/edited _csv.js | 22 ++++++++++++++++++++++ templates/csv_preview.html | 25 +------------------------ 3 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 static/edited _csv.js diff --git a/routes/confirm_save.py b/routes/confirm_save.py index 632300f..2dfc587 100644 --- a/routes/confirm_save.py +++ b/routes/confirm_save.py @@ -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'], diff --git a/static/edited _csv.js b/static/edited _csv.js new file mode 100644 index 0000000..b3b7177 --- /dev/null +++ b/static/edited _csv.js @@ -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); +} \ No newline at end of file diff --git a/templates/csv_preview.html b/templates/csv_preview.html index be812e2..f56dbfd 100644 --- a/templates/csv_preview.html +++ b/templates/csv_preview.html @@ -4,30 +4,7 @@ CSV Preview - +

CSV Preview