split up secitons for lines with parents and those without

enable update vendor on enter
This commit is contained in:
Yisroel Baum 2024-10-29 15:24:05 +02:00
parent ce2c163abe
commit bb7bc37a3e
2 changed files with 98 additions and 23 deletions

View file

@ -1,14 +1,15 @@
const monthSelector = document.getElementById('month-selector');
const tableBody = document.getElementById('table-body');
const childTableBody = document.getElementById('child-table-body');
var reassignButtons = document.getElementsByClassName('reassign-button');
function startEditMode(id){
async function startEditMode(id){
for(let i = 0; i < reassignButtons.length; i++){
reassignButtons[i].disabled = true;
}
const handleKeydown = (e) => {
const handleKeydown = async (e) => {
if (e.key === 'Enter') {
document.removeEventListener('keydown', handleKeydown);
const vendor = document.getElementById(`vendor-line-${id}`);
@ -17,7 +18,8 @@ function startEditMode(id){
if (vendorInput.parentNode) {
vendorInput.parentNode.removeChild(vendorInput);
}
var result = await fetch(`/update_vendor/${id}/${vendor.innerText}`, {method:'POST'});
var data = await result.json();
for(let i = 0; i < reassignButtons.length; i++){
reassignButtons[i].disabled = false;
}
@ -41,24 +43,43 @@ async function displayMonthLineItems(dateString){
var result = await fetch(`/get_month_line_items/${month}/${year}`, {method:'POST'});
var data = await result.json();
tableBody.innerHTML = ''
childTableBody.innerHTML = ''
data.forEach(li => {
const row = `
<tr id="${li.id}-row">
<th scope="row">${li.id}</th>
<th scope="row">${li.parent_line_item_id || ''}</th>
<th scope="row">${li.amount}</th>
<th scope="row">${li.currency_type}</th>
<th scope="row" id="vendor-line-${li.id}">${li.vendor}</th>
<th scope="row">${li.date}</th>
<th scope="row">${li.confirmation_code}</th>
<th scope="row">${li.note || ''}</th>
<th scope="row"><button id="${li.id}" class="btn btn-primary reassign-button">Click to reassign vendor</button></th>
<th scope="row"><a class="btn btn-primary" href="/split_line/${li.id}">Click to split line</a></th>
</tr>
`;
// Insert the row into the table body
tableBody.insertAdjacentHTML('beforeend', row);
if (!li.parent_line_item_id){
const row = `
<tr id="${li.id}-row">
<th scope="row">${li.id}</th>
<th scope="row">${li.amount}</th>
<th scope="row">${li.currency_type}</th>
<th scope="row" id="vendor-line-${li.id}">${li.vendor}</th>
<th scope="row">${li.date}</th>
<th scope="row">${li.confirmation_code}</th>
<th scope="row">${li.note || ''}</th>
<th scope="row"><button id="${li.id}" class="btn btn-primary reassign-button">Click to reassign vendor</button></th>
<th scope="row"><a class="btn btn-primary" href="/split_line/${li.id}">Click to split line</a></th>
</tr>
`;
// Insert the row into the table body
tableBody.insertAdjacentHTML('beforeend', row);
} else {
const row = `
<tr id="${li.id}-row">
<th scope="row">${li.id}</th>
<th scope="row">${li.parent_line_item_id}</th>
<th scope="row">${li.amount}</th>
<th scope="row">${li.currency_type}</th>
<th scope="row" id="vendor-line-${li.id}">${li.vendor}</th>
<th scope="row">${li.date}</th>
<th scope="row">${li.confirmation_code}</th>
<th scope="row">${li.note || ''}</th>
<th scope="row"><button id="${li.id}" class="btn btn-primary reassign-button">Click to reassign vendor</button></th>
</tr>
`;
// Insert the row into the table body
childTableBody.insertAdjacentHTML('beforeend', row);
}
});
addListenersToReassignButtons();