workin on document creation: frontend work
This commit is contained in:
37
frontend/src/Components/ContactSelector.svelte
Normal file
37
frontend/src/Components/ContactSelector.svelte
Normal file
@@ -0,0 +1,37 @@
|
||||
<script>
|
||||
import {onMount} from 'svelte';
|
||||
import {t} from '../translations.svelte.js';
|
||||
let { caption, onselect = (contact) => console.log('selected '+contact.FN||contact.ORG) } = $props();
|
||||
let message = t('contacts.loading');
|
||||
let contacts = $state(null);
|
||||
let value = 0;
|
||||
|
||||
async function loadContacts(){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/contacts`;
|
||||
var resp = await fetch(url,{ credentials: 'include'});
|
||||
if (resp.ok){
|
||||
contacts = await resp.json();
|
||||
} else {
|
||||
message = await resp.text();
|
||||
}
|
||||
}
|
||||
|
||||
function select(){
|
||||
onselect(contacts[value]);
|
||||
}
|
||||
|
||||
onMount(loadContacts)
|
||||
|
||||
</script>
|
||||
|
||||
{#if contacts}
|
||||
<select onchange={select} bind:value>
|
||||
<option value={0}>{caption}</option>
|
||||
{#each contacts as contact,idx}
|
||||
<option value={idx}>{contact.FN||contact.ORG}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{:else}
|
||||
<span>{message}</span>
|
||||
{/if}
|
||||
|
||||
@@ -14,7 +14,6 @@ async function fetchModules(){
|
||||
if (resp.ok){
|
||||
const arr = await resp.json();
|
||||
for (let entry of arr) modules.push({name:t('menu.'+entry.module),url:entry.url});
|
||||
console.log(modules);
|
||||
} else {
|
||||
console.log('error');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user