working on autocomplete fields
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
name : '',
|
||||
currency : ''
|
||||
};
|
||||
let { account = defaultAccount, new_account = false } = $props();
|
||||
let { account = defaultAccount, new_account = false, onSave = () => {} } = $props();
|
||||
|
||||
let entry = $state({
|
||||
account,
|
||||
@@ -27,12 +27,22 @@
|
||||
});
|
||||
let router = useTinyRouter();
|
||||
|
||||
function mapDisplay(object){
|
||||
if (object.display){
|
||||
return object;
|
||||
} else if (object.name) {
|
||||
return {...object, display: object.name};
|
||||
} else {
|
||||
return { display : object }
|
||||
}
|
||||
}
|
||||
|
||||
async function getTerminal(text,url){
|
||||
var res = await post(url,text);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
const input = await res.json();
|
||||
return Object.values(input).map(user => { return {...user, display: user.name}});
|
||||
return Object.values(input).map(mapDisplay);
|
||||
} else {
|
||||
error(res);
|
||||
return {};
|
||||
@@ -44,6 +54,11 @@
|
||||
return await getTerminal(text,url);
|
||||
}
|
||||
|
||||
async function getPurposes(text) {
|
||||
var url = api('accounting/purposes');
|
||||
return await getTerminal(text,url);
|
||||
}
|
||||
|
||||
async function getSources(text){
|
||||
var url = api('accounting/sources');
|
||||
return await getTerminal(text,url);
|
||||
@@ -58,7 +73,8 @@
|
||||
let res = await post(url, data);
|
||||
if (res.ok) {
|
||||
yikes();
|
||||
router.navigate('/accounting');
|
||||
onSave();
|
||||
document.getElementById('date-input').focus();
|
||||
} else error(res);
|
||||
}
|
||||
</script>
|
||||
@@ -74,6 +90,8 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<span class="warn">TODO: Tagging von Umsätzen</span>
|
||||
|
||||
<fieldset class="grid2">
|
||||
{#if new_account}
|
||||
<legend>{t('create_new_object',{object:t('account')})}</legend>
|
||||
@@ -95,11 +113,11 @@
|
||||
|
||||
<span>{t('date')}</span>
|
||||
<span>
|
||||
<input type="date" value={entry.date} />
|
||||
<input type="date" bind:value={entry.date} id="date-input" />
|
||||
</span>
|
||||
|
||||
<span>{t('source')}</span>
|
||||
<Autocomplete bind:candidate={entry.source} getCandidates={getSources} />
|
||||
<Autocomplete bind:candidate={entry.source} getCandidates={getSources} id="source-input" />
|
||||
|
||||
<span>{t('destination')}</span>
|
||||
<Autocomplete bind:candidate={entry.destination} getCandidates={getDestinations} />
|
||||
@@ -110,10 +128,10 @@
|
||||
</span>
|
||||
|
||||
<span>{t('purpose')}</span>
|
||||
<Autocomplete bind:candidate={entry.purpose} />
|
||||
<Autocomplete bind:candidate={entry.purpose} getCandidates={getPurposes} />
|
||||
|
||||
<span></span>
|
||||
<span>
|
||||
<button onclick={save}>{t('save')}</button>
|
||||
</span>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
Reference in New Issue
Block a user