working on company editing

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-08-07 15:42:01 +02:00
parent 19f9f466b8
commit abfed21393
5 changed files with 241 additions and 18 deletions

View File

@@ -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>