5 changed files with 241 additions and 18 deletions
@ -1,7 +1,69 @@
@@ -1,7 +1,69 @@
|
||||
<script> |
||||
import {t} from '../../translations.svelte.js'; |
||||
import {onMount} from 'svelte'; |
||||
import {api} from '../../urls.svelte.js'; |
||||
import {t} from '../../translations.svelte.js'; |
||||
|
||||
import Editor from './Editor.svelte'; |
||||
|
||||
let companies = $state(null); |
||||
let error = $state(null); |
||||
let selected = $state(0); |
||||
|
||||
async function loadCompanies(){ |
||||
const url = api('company/list'); |
||||
const resp = await fetch(url,{credentials:'include'}); |
||||
if (resp.ok){ |
||||
companies = await resp.json(); |
||||
console.log(companies); |
||||
error = null; |
||||
} else { |
||||
error = await resp.text(); |
||||
} |
||||
} |
||||
|
||||
function showDetail(company_id){ |
||||
selected = company_id; |
||||
} |
||||
|
||||
onMount(loadCompanies) |
||||
</script> |
||||
|
||||
<fieldset> |
||||
<legend>{t('companies')}</legend> |
||||
{#if error} |
||||
<span class="error">{error}</span> |
||||
{/if} |
||||
{#if companies} |
||||
<table class="companies"> |
||||
<thead> |
||||
<tr> |
||||
<th> |
||||
{t('name')} |
||||
</th> |
||||
<th> |
||||
{t('email')} |
||||
</th> |
||||
<th> |
||||
{t('detail')} |
||||
</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
{#each Object.entries(companies) as [cid, company]} |
||||
<tr onclick={e => showDetail(cid)}> |
||||
<td>{company.name}</td> |
||||
<td>{company.email}</td> |
||||
<td>{company.address.replace('\r','').replace('\n',' / ')}</td> |
||||
</tr> |
||||
{#if selected==cid} |
||||
<tr> |
||||
<td colspan="3"> |
||||
<Editor {company} /> |
||||
</td> |
||||
</tr> |
||||
{/if} |
||||
{/each} |
||||
</tbody> |
||||
</table> |
||||
{/if} |
||||
</fieldset> |
||||
Loading…
Reference in new issue