git ssb

0+

punkmonk / double



Tree: 8a55ce7a0a9c8d857b3bf814582e7c20674d2f22

Files: 8a55ce7a0a9c8d857b3bf814582e7c20674d2f22 / views / entries.js

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

Built with git-ssb-web