Files: 543423934bab207e903927a812ea891b52c1f438 / views / entries.js
1647 bytesRaw
1 | const fs = require('fs') |
2 | const path = require('path') |
3 | const h = require('hyperscript') |
4 | const TITLE = 'double - entries' |
5 | const Nav = require('../components/nav') |
6 | |
7 | function view (state, emit) { |
8 | if (state.title !== TITLE) emit(state.events.DOMTITLECHANGE, TITLE) |
9 | |
10 | const form = h('form.pv3', [ |
11 | h('div.pb2', [ |
12 | h('label', 'debit account'), |
13 | h('div', h('select#debit', [ |
14 | h('option', {value: 'true'},'select'), |
15 | generateAccountList() |
16 | ])) |
17 | ]), |
18 | h('div.pb2', [ |
19 | h('label', 'credit account'), |
20 | h('div', h('select#credit', [ |
21 | h('option', {value: 'true'},'select'), |
22 | generateAccountList() |
23 | ])) |
24 | ]), |
25 | h('div', h('input#amount.mb2', {placeholder: 'amount'})), |
26 | h('div', h('input#description', {placeholder: 'description'})) |
27 | ]) |
28 | |
29 | const submit = h('div.pb3', h('button', {onclick: handleEntry}, 'submit')) |
30 | |
31 | return h('body.code.ph3.lh-copy', [ |
32 | state.cache(Nav, 'nav').render(), |
33 | h('main', [ |
34 | form, |
35 | submit |
36 | ]), |
37 | ]) |
38 | |
39 | |
40 | function generateAccountList () { |
41 | return Object.keys(state.accounts).map(key => { |
42 | if (state.accounts[key].archived) return |
43 | const name = state.accounts[key].name |
44 | return h('option', {value: name}, name) |
45 | }) |
46 | } |
47 | |
48 | function handleEntry () { |
49 | const amount = parseFloat(document.getElementById('amount').value) |
50 | const debit = document.getElementById('debit').value |
51 | const credit = document.getElementById('credit').value |
52 | const description = document.getElementById('description').value |
53 | |
54 | emit('entries', { type: 'entries', msg: { amount, debit, credit, description } }) |
55 | } |
56 | |
57 | } |
58 | |
59 | module.exports = view |
60 |
Built with git-ssb-web