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

@@ -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');