working on new location creation
This commit is contained in:
@@ -76,7 +76,7 @@
|
||||
{#each top_level as realm,idx}
|
||||
<h3>{realm.name}</h3>
|
||||
{#if realm.locations}
|
||||
<Locations locations={realm.locations} bind:selected={location} />
|
||||
<Locations locations={realm.locations} parent={realm} bind:selected={location} />
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
let { locations, selected = $bindable(null) } = $props();
|
||||
import LineEditor from '../../Components/LineEditor.svelte';
|
||||
|
||||
let { locations, parent = null, selected = $bindable(null) } = $props();
|
||||
|
||||
let show_location_form = $state(false);
|
||||
let new_location_name = $state(null);
|
||||
|
||||
async function toggleChildren(ev, location){
|
||||
ev.preventDefault();
|
||||
@@ -21,20 +26,47 @@
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function onsubmit(ev){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
const data = {
|
||||
name: new_location_name,
|
||||
parent: parent.user ? {user:parent.user} : {company:parent.company}
|
||||
}
|
||||
|
||||
console.log(data);
|
||||
}
|
||||
|
||||
function show_loc_form(ev){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
show_location_form = true;
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a>
|
||||
{#if show_location_form}
|
||||
<form {onsubmit}>
|
||||
<input type="text" placeholder={t('new_location_name')} bind:value={new_location_name} />
|
||||
</form>
|
||||
{:else}
|
||||
<a onclick={show_loc_form}>
|
||||
<span class="symbol"></span> {t('add_object',{object:t('location')})}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
</li>
|
||||
{#each locations as location}
|
||||
<li onclick={e => toggleChildren(e, location)} class={location.locations?'expanded':'collapsed'}>
|
||||
{location.name}
|
||||
{#if location.locations}
|
||||
<svelte:self locations={location.locations} bind:selected />
|
||||
<svelte:self locations={location.locations} parent={location} bind:selected />
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</ul>
|
||||
<!-- <pre>{JSON.stringify(parent,null,2)}</pre> -->
|
||||
Reference in New Issue
Block a user