Files
Umbrella/frontend/src/routes/accounting/index.svelte
2026-04-09 09:12:57 +02:00

51 lines
1.0 KiB
Svelte

<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { t } from '../../translations.svelte';
import { api, get } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
const router = useTinyRouter();
let accounts = [];
async function load(){
let url = api('accounting');
let res = await get(url);
if (res.ok){
yikes();
accounts = await res.json();
} else error(res);
}
function newAccount(){
router.navigate('/accounting/new');
}
function onclick(e){
e.preventDefault();
let href = e.target.getAttribute('href');
if (href) router.navigate(href);
return false;
}
onMount(load);
</script>
<fieldset>
<span></span>
<span>
<button onclick={newAccount}>{t('create_new_object',{'object':t('account')})}</button>
</span>
<ul>
{#each accounts as account (account.id)}
<li>
<a {onclick} href="/account/{account.id}">{account.name} ({account.id})</a>
</li>
{/each}
</ul>
<legend>{t('accounts')}</legend>
</fieldset>