implemented cloning of stock items. NEXT: update of GUI via message bus
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import LineEditor from '../../Components/LineEditor.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { api } from '../../urls.svelte';
|
||||
import { api, patch, post } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
@@ -15,6 +15,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
async function doClone(ev){
|
||||
let url = api('stock/clone');
|
||||
let res = await post(url,{id:item.id});
|
||||
if (res.ok){
|
||||
let json = await res.json();
|
||||
yikes(res);
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
function byName(a,b){
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
@@ -30,11 +39,7 @@
|
||||
},
|
||||
add_prop : add_prop
|
||||
}
|
||||
const res = await fetch(url,{
|
||||
credentials:'include',
|
||||
method:'POST',
|
||||
body:JSON.stringify(data)
|
||||
});
|
||||
const res = await post(url,data);
|
||||
if (res.ok){
|
||||
const prop = await res.json();
|
||||
const id = prop.id;
|
||||
@@ -45,18 +50,14 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
async function patch(key,newVal){
|
||||
async function update(key,newVal){
|
||||
const url = api('stock');
|
||||
const data = {
|
||||
id : item.id,
|
||||
owner : item.owner,
|
||||
};
|
||||
data[key] = newVal;
|
||||
const res = await fetch(url,{
|
||||
credentials:'include',
|
||||
method:'PATCH',
|
||||
body:JSON.stringify(data)
|
||||
});
|
||||
const res = await patch(url,data);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
return true;
|
||||
@@ -67,13 +68,19 @@
|
||||
</script>
|
||||
|
||||
{#if item}
|
||||
<LineEditor type="h3" editable={true} value={item.name} onSet={v => patch('name',v)} />
|
||||
Code: <LineEditor type="span" editable={true} value={item.code} onSet={v => patch('code',v)} />
|
||||
<LineEditor type="h3" editable={true} value={item.name} onSet={v => update('name',v)} />
|
||||
<button class="clone symbol" title={t('clone')} onclick={doClone}>C</button>
|
||||
<div>
|
||||
{@html item.description.rendered}
|
||||
</div>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{t('Code')}:</td>
|
||||
<td>
|
||||
<LineEditor type="span" editable={true} value={item.code} onSet={v => update('code',v)} />
|
||||
</td>
|
||||
</tr>
|
||||
{#each item.properties.toSorted(byName) as prop}
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user