implemented GUI update on cloning items
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,11 +1,39 @@
|
||||
<script>
|
||||
import { api, post } from '../../urls.svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { api, eventStream, post } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
let { items, selected = $bindable(null), location = null, drag_start = item => console.log({dragging:item}) } = $props();
|
||||
let eventSource = null;
|
||||
let newItem = $state({name:null, code: null});
|
||||
|
||||
function handleCreateEvent(evt){
|
||||
let json = JSON.parse(evt.data);
|
||||
if (json.item.location.id == location.id){
|
||||
items = [...items,json.item];
|
||||
selected = json.item;
|
||||
}
|
||||
}
|
||||
|
||||
function handleEvent(evt,method){
|
||||
console.log(evt,method);
|
||||
}
|
||||
|
||||
function handleDeleteEvent(evt){
|
||||
handleEvent(evt,'delete');
|
||||
}
|
||||
|
||||
function handleUpdateEvent(evt){
|
||||
handleEvent(evt,'update');
|
||||
}
|
||||
|
||||
function load(){
|
||||
try {
|
||||
eventSource = eventStream(handleCreateEvent,handleUpdateEvent,handleDeleteEvent);
|
||||
} catch (ignored) {}
|
||||
}
|
||||
|
||||
async function saveNewItem(){
|
||||
newItem.location = location;
|
||||
const url = api('stock/item');
|
||||
@@ -17,6 +45,12 @@
|
||||
items = [...items, it];
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
if (eventSource) eventSource.close();
|
||||
});
|
||||
onMount(load);
|
||||
|
||||
</script>
|
||||
<table>
|
||||
<thead>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
{#if item}
|
||||
<LineEditor type="h3" editable={true} value={item.name} onSet={v => update('name',v)} />
|
||||
<button class="clone symbol" title={t('clone')} onclick={doClone}>C</button>
|
||||
<button class="clone symbol" title={t('clone')} onclick={doClone}></button>
|
||||
<div>
|
||||
{@html item.description.rendered}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user