all repos — piggy @ 693d77e1f7f4d3cc8f8da2e000d408ec3b1950ac

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", "Exchange", "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                    formatBoolean(bookmaker.exchange),
44                    bookmaker.default_commission,
45                ];
46
47                for (const field of fields) {
48                    const td = document.createElement('td');
49                    td.innerHTML = field;
50                    tr.appendChild(td);
51                }
52                table.appendChild(tr);
53            }
54        });
55}