implemented deletion of locations

This commit is contained in:
2025-10-21 10:17:09 +02:00
parent 59e6a7001d
commit 6c7fbdcde2
6 changed files with 96 additions and 16 deletions

View File

@@ -21,8 +21,12 @@
async function applyEdit(){
let success = await onSet(editValue);
if (success) value = editValue;
editing=false;
if (success) {
value = editValue;
editing=false;
} else {
editValue = value;
}
}
function ignore(evt){

View File

@@ -22,6 +22,32 @@
let properties = $state(null);
let top_level = $state(null);
async function deleteLocation(loc){
if (!confirm(t('confirm_delete',{element:loc.name}))) return;
const url = api(`stock/location/${loc.id}`);
const res = await fetch(url,{
credentials: 'include',
method: 'DELETE',
});
if (res.ok){
yikes();
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,loc)) break;
}
} else error(res);
}
function dropNestedLocation(locations,loc){
for (let [idx,entry] of locations.entries()){
if (entry.id == loc.id){
locations.splice(idx,1);
return true;
}
if (entry.locations && dropNestedLocation(entry.locations,loc)) return true;
}
return false;
}
async function move_dragged_to(new_loc){
const data = { item : draggedItem.id, target: new_loc.id };
const url = api('stock/move_item');

View File

@@ -39,6 +39,10 @@
return false;
}
function reset(){
new_location_name = '';
}
async function onSet(new_location_name){
const data = {
name: new_location_name,
@@ -54,6 +58,8 @@
yikes;
const saved = await res.json();
locations.push(saved);
show_location_form = false;
setTimeout(reset,500);
return true;
} else {
error(res);
@@ -86,18 +92,6 @@
</style>
<ul>
<li>
{#if show_location_form}
<form {onsubmit}>
<LineEditor simple={true} bind:value={new_location_name} {onSet} />
</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.highlight?'highlight':null}"
@@ -110,5 +104,17 @@
{/if}
</li>
{/each}
<li>
{#if show_location_form}
<form {onsubmit}>
<LineEditor simple={true} bind:value={new_location_name} {onSet} />
</form>
{:else}
<a onclick={show_loc_form}>
<span class="symbol"></span> {t('add_object',{object:t('location')})}
</a>
{/if}
</li>
</ul>
<!-- <pre>{JSON.stringify(parent,null,2)}</pre> -->
<!-- <pre>{JSON.stringify(parent,null,2)}</pre> -->