refactored moving of locations, implemented editing of location details, implemented raising locations to the top level

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-22 23:36:42 +02:00
parent 8bf0790fca
commit a73a660d43
6 changed files with 45 additions and 11 deletions

View File

@@ -4,9 +4,11 @@
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import Locations from './Locations.svelte';
import ItemList from './ItemList.svelte';
import ItemProps from './ItemProps.svelte';
import LineEditor from '../../Components/LineEditor.svelte';
import Locations from './Locations.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import Notes from '../notes/RelatedNotes.svelte';
import Tags from '../tags/TagList.svelte';
@@ -122,6 +124,25 @@
loadProperties();
}
async function patchLocation(location,field,newValue){
const data = {};
data[field] = newValue;
console.log(data);
const url = api(`stock/location/${location.id}`);
const res = await fetch(url,{
credentials: 'include',
method:'PATCH',
body:JSON.stringify(data)
});
if (res.ok){
yikes();
return true;
} else {
error(res);
return false;
}
}
onMount(load);
</script>
@@ -147,7 +168,14 @@
{:then data}
<div class="items">
{#if location}
<h3>{location.name} <button class="symbol" title={t('delete_object',{object:t('location')})} onclick={e => deleteLocation(location)}></button></h3>
<h3>
<LineEditor editable={true} bind:value={location.name} type="span" onSet={newName => patchLocation(location,'name',newName)} />
<button class="symbol" title={t('delete_object',{object:t('location')})} onclick={e => deleteLocation(location)}></button>
{#if location.parent_location_id}
<button class="symbol" title={t('move_to_top')} onclick={e => patchLocation(location,'parent_location_id',0)}></button>
{/if}
</h3>
<MarkdownEditor editable={true} value={location.description} type="div" onSet={newDesc => patchLocation(location,'description',newDesc)} />
{/if}
<ItemList items={data?.items.sort((a,b) => a.code.localeCompare(b.code))} bind:selected={item} drag_start={drag_item} />
</div>