Browse Source

Merge branch 'module/stock' into dev

module/document
Stephan Richter 2 weeks ago
parent
commit
19451c705f
  1. 26
      frontend/src/routes/stock/Index.svelte
  2. 2
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

26
frontend/src/routes/stock/Index.svelte

@ -34,10 +34,14 @@ @@ -34,10 +34,14 @@
});
if (res.ok){
yikes();
unlistLocation(loc);
} else error(res);
}
function unlistLocation(loc){
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,loc)) break;
}
} else error(res);
}
function drag_item(item){
@ -72,11 +76,7 @@ @@ -72,11 +76,7 @@
if (res.ok){
yikes();
location = new_loc;
if (!draggedItem){
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,draggedLocation)) break;
}
}
if (!draggedItem) unlistLocation(draggedLocation);
draggedItem = null;
draggedLocation = null;
} else {
@ -124,6 +124,18 @@ @@ -124,6 +124,18 @@
loadProperties();
}
function moveToTop(loc){
if (patchLocation(location,'parent_location_id',0)){
loc.parent_location_id = 0;
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,loc)) {
owner.locations.push(loc);
break;
};
}
}
}
async function patchLocation(location,field,newValue){
const data = {};
data[field] = newValue;
@ -172,7 +184,7 @@ @@ -172,7 +184,7 @@
<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>
<button class="symbol" title={t('move_to_top')} onclick={e => moveToTop(location)}></button>
{/if}
</h3>
<MarkdownEditor editable={true} value={location.description} type="div" onSet={newDesc => patchLocation(location,'description',newDesc)} />

2
stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

@ -250,9 +250,11 @@ public class StockModule extends BaseHandler implements StockService { @@ -250,9 +250,11 @@ public class StockModule extends BaseHandler implements StockService {
if (json.has(PARENT_LOCATION_ID) && json.get(PARENT_LOCATION_ID) instanceof Number parentId){
if (parentId.longValue() != 0L) {
var target = stockDb.loadLocation(parentId.longValue());
if (target.id() == location.id()) throw forbidden("Location must not be it`s own parent!");
var targetOwner = target.owner().resolve();
if (!assigned(targetOwner, user)) throw forbidden("You are not allowed to edit \"{0}\"!", target.name());
if (!targetOwner.equals(owner)) throw unprocessable("You may not move locations from one owner ({0}) to another ({1})", owner, targetOwner);
LOG.log(WARNING,"Not checking, if location is moved to on of its own children!");
}
}

Loading…
Cancel
Save