From f5054aea47bfcb1d15f7ffc35762fe80a303ecc0 Mon Sep 17 00:00:00 2001 From: ydb5755 Date: Wed, 9 Oct 2024 14:39:49 +0300 Subject: [PATCH] displaying rows from api call to get line items of month --- app/static/homepage.js | 45 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/app/static/homepage.js b/app/static/homepage.js index ce3e8b0..f81b21b 100644 --- a/app/static/homepage.js +++ b/app/static/homepage.js @@ -1,4 +1,7 @@ -const reassignButtons = document.getElementsByClassName('reassign-button'); +const monthSelector = document.getElementById('month-selector'); +const tableBody = document.getElementById('table-body'); +var reassignButtons = document.getElementsByClassName('reassign-button'); + function startEditMode(id){ for(let i = 0; i < reassignButtons.length; i++){ @@ -33,10 +36,46 @@ function startEditMode(id){ inputElem.focus() } -document.addEventListener("DOMContentLoaded", (event) => { +async function displayMonthLineItems(dateString){ + const [month, year] = dateString.split(' '); + var result = await fetch(`/get_month_line_items/${month}/${year}`, {method:'POST'}); + var data = await result.json(); + tableBody.innerHTML = '' + data.forEach(li => { + const row = ` + + ${li.id} + ${li.parent_line_item_id} + ${li.amount} + ${li.currency_type} + ${li.vendor} + ${li.date} + ${li.confirmation_code} + ${li.note} + + Click to split line + + `; + + // Insert the row into the table body + tableBody.insertAdjacentHTML('beforeend', row); + + }); + addListenersToReassignButtons(); +} + +function addListenersToReassignButtons() { + reassignButtons = document.getElementsByClassName('reassign-button'); for(let i = 0; i < reassignButtons.length; i++){ reassignButtons[i].addEventListener('click', e => { - startEditMode(parseInt(e.target.id)) + startEditMode(parseInt(e.target.id)); }) } +} + +document.addEventListener("DOMContentLoaded", (event) => { + displayMonthLineItems(monthSelector.value); + monthSelector.addEventListener('change', (e) => { + displayMonthLineItems(e.target.value); + }) }); \ No newline at end of file