ui can create transaction, submits text instead of html

master
Bel LaPointe 2021-08-30 11:14:41 -04:00
parent 1345071f0a
commit 3e9349078c
1 changed files with 30 additions and 1 deletions

View File

@ -2,6 +2,15 @@
<header>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
<style>
body > div {
width: 100%;
}
.center {
text-align: center;
}
.right {
text-align: right;
}
#transactions > tbody > tr > td:first-child input {
padding: 1ch;
display: inline-block;
@ -93,6 +102,25 @@
document.getElementById("transactions").innerHTML = innerHTML
}
function newTransaction() {
var today = new Date()
var year = today.getFullYear()
var month = today.getMonth()+1
var day = today.getDate()
if (day < 10) {
day = `0${day}`
}
if (month < 10) {
month = `0${month}`
}
http("post", "/api/transactions", () => {init()}, JSON.stringify({
Date: `${year}-${month}-${day}`,
Description: "?",
Payer: "?",
Payee: "?",
Amount: 0,
}))
}
function saveTransaction(row) {
const inputs = row.getElementsByTagName("td")
var kvs = {}
@ -101,7 +129,7 @@
if (!key) {
continue
}
const value = inputs[i].innerHTML
const value = (inputs[i].textContent || inputs[i].innerText).replaceAll("\n", " ").trim()
kvs[key] = value
if (!isNaN(value))
kvs[key] = parseFloat(value)
@ -145,6 +173,7 @@
<summary>Balances</summary>
<div id="balances"></div>
</details>
<div class="right"><button onclick="newTransaction();">New Transaction</button></div>
<table id="transactions"></table>
</body>
<footer>