implemented deletion of locations
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user