preparing to store new locations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-20 23:17:54 +02:00
parent 6158fb2630
commit 4e9c8c0f69
5 changed files with 59 additions and 9 deletions

View File

@@ -92,7 +92,7 @@
{#each top_level as realm,idx}
<h3>{realm.name}</h3>
{#if realm.locations}
<Locations locations={realm.locations} bind:selected={location} {move_dragged_to} />
<Locations locations={realm.locations} parent={realm.parent} bind:selected={location} {move_dragged_to} />
{/if}
{/each}
{/if}

View File

@@ -5,7 +5,7 @@
import LineEditor from '../../Components/LineEditor.svelte';
let { locations, move_dragged_to = new_loc => {}, selected = $bindable(null) } = $props();
let { locations, move_dragged_to = new_loc => {}, parent = null, selected = $bindable(null) } = $props();
let show_location_form = $state(false);
let new_location_name = $state(null);
@@ -39,14 +39,35 @@
return false;
}
async function onSet(new_location_name){
const data = {
name: new_location_name,
parent: parent
}
const url = api('stock/location');
const res = await fetch(url,{
credentials: 'include',
method: 'POST',
body: JSON.stringify(data)
});
if (res.ok){
yikes;
return true;
} else {
error(ok);
return false;
}
}
function onsubmit(ev){
ev.preventDefault();
ev.stopPropagation();
const data = {
name: new_location_name,
parent: parent.user ? {user:parent.user} : {company:parent.company}
parent: parent
}
console.log(JSON.parse(JSON.stringify(data)));
}
function show_loc_form(ev){
@@ -67,7 +88,7 @@
<li>
{#if show_location_form}
<form {onsubmit}>
<input type="text" placeholder={t('new_location_name')} bind:value={new_location_name} />
<LineEditor simple={true} bind:value={new_location_name} {onSet} />
</form>
{:else}
<a onclick={show_loc_form}>
@@ -84,7 +105,7 @@
ondragleave={e => delete location.highlight}>
<span class="name">{location.name}</span>
{#if location.locations}
<svelte:self locations={location.locations} {move_dragged_to} bind:selected />
<svelte:self locations={location.locations} {move_dragged_to} parent={{location:location.id}} bind:selected />
{/if}
</li>
{/each}