all repos — piggy @ 1a0ce761ef68d0800a69ebff7968d2c655aba6f3

Dead simple finance manager in Go, HTML and JS.

static/js/bookmakers.js (view raw)

 1document.addEventListener('DOMContentLoaded', function () {
 2    loadBookmakers();
 3
 4    document.getElementById('new-bookmaker').addEventListener('click', editBookmaker);
 5});
 6
 7function editBookmaker() {
 8    let out = "/bookmakers/edit/";
 9    const id = this.getAttribute("data-id");
10    if (id) {
11        out += "?id=" + id;
12    }
13    location.href = out;
14}
15
16function loadBookmakers() {
17    getBookmakers().then(bookmakers => {
18            const header = document.getElementById('bookmakers-header');
19            const table = document.getElementById('bookmakers-table');
20            header.innerHTML = '';
21            table.innerHTML = '';
22
23            const tr = document.createElement('tr');
24            const headers = ["ID", "Created", "Updated", "Name", "Commission"];
25
26            for (const header of headers) {
27                const td = document.createElement('td');
28                td.innerText = header;
29                tr.appendChild(td);
30            }
31            header.appendChild(tr);
32
33            for (const bookmaker of bookmakers) {
34                const tr = document.createElement('tr');
35                tr.setAttribute("data-id", bookmaker.id);
36                tr.onclick = editBookmaker;
37
38                const fields = [
39                    bookmaker.id,
40                    formatDate(bookmaker.created_at),
41                    formatDate(bookmaker.updated_at),
42                    bookmaker.name,
43                    formatPercentage(bookmaker.default_commission),
44                ];
45
46                for (const field of fields) {
47                    const td = document.createElement('td');
48                    td.innerHTML = field;
49                    tr.appendChild(td);
50                }
51                table.appendChild(tr);
52            }
53        });
54}