Files: 8a55ce7a0a9c8d857b3bf814582e7c20674d2f22 / views / accounts.js
1680 bytesRaw
1 | const h = require('hyperscript') |
2 | const TITLE = 'double - acounts' |
3 | const Nav = require('../components/nav') |
4 | const Styles = require('../components/styles') |
5 | |
6 | function accountsView (state, emit) { |
7 | return h('body.code.ph3.lh-copy', [ |
8 | state.cache(Styles, 'styles').render(), |
9 | state.cache(Nav, 'nav').render(), |
10 | h('table.center', [ |
11 | h('thead', h('tr', [ |
12 | h('td.pr2.red', 'account'), |
13 | h('td.pr2', 'balance') |
14 | ])), |
15 | h('tbody', Object.keys(state.accounts).map(key => { |
16 | return state.accounts[key].archived |
17 | ? h('tr', [ |
18 | h('td.strike', {onclick: handleAccountArchive}, state.accounts[key].name), |
19 | h('td.tr.strike', state.accounts[key].debit - state.accounts[key].credit) |
20 | ]) |
21 | : h('tr', [ |
22 | h('td', {onclick: handleAccountArchive}, state.accounts[key].name), |
23 | h('td.tr', state.accounts[key].debit - state.accounts[key].credit) |
24 | ]) |
25 | })) |
26 | ]), |
27 | h('div.tc', [ |
28 | h('div.pt4', 'create a new account'), |
29 | h('form.pb3', h('input#account', {placeholder: 'account name'})), |
30 | h('button', { onclick: handleAccountCreate }, 'create') |
31 | ]) |
32 | ]) |
33 | |
34 | function handleAccountCreate () { |
35 | const name = document.getElementById('account').value |
36 | |
37 | emit('accounts', { type: 'accounts', msg: { name, debit: 0, credit: 0, archived: false } }) |
38 | } |
39 | |
40 | function handleAccountArchive () { |
41 | const name = this.innerHTML |
42 | if (state.accounts[name].archived) { |
43 | return emit('accounts', { type: 'accounts', msg: { name, archived: false } }) |
44 | } |
45 | emit('accounts', { type: 'accounts', msg: { name, archived: true } }) |
46 | } |
47 | } |
48 | |
49 | module.exports = accountsView |
50 |
Built with git-ssb-web