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