preparing creation of successor document

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-08-30 17:19:51 +02:00
parent 7b5ea62bfd
commit 8d16a93b69
6 changed files with 86 additions and 76 deletions

View File

@@ -15,6 +15,7 @@
import StateSelector from './StateSelector.svelte';
import Tags from '../tags/TagList.svelte';
import TemplateSelector from './TemplateSelector.svelte';
import TypeSelector from './TypeSelector.svelte';
let doc = $state(null);
@@ -26,13 +27,16 @@
const router = useTinyRouter();
let sndDisabled = $state(false);
async function loadDoc(){
const url = api(`document/${id}`);
const resp = await fetch(url,{credentials:'include'});
async function addPosition(selected){
const url = api(`document/${doc.id}/position`);
const resp = await fetch(url,{
method : 'POST',
credentials : 'include',
body : JSON.stringify(selected)
});
if (resp.ok){
doc = await resp.json();
error = null;
doc.positions = await resp.json();
error = null;
} else {
error = await resp.text();
}
@@ -52,38 +56,16 @@
}
}
async function update(path,newValue){
const parts = path.split('.');
if (parts.length<1) return false;
let data = newValue;
while (parts.length > 0){
const inner = data;
data = {};
data[parts.pop()] = inner;
}
try {
const url = api(`document/${doc.id}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
return resp.ok;
} catch (err){
return false;
}
function createSuccessorDoc(type){
console.log(type);
}
async function addPosition(selected){
const url = api(`document/${doc.id}/position`);
const resp = await fetch(url,{
method : 'POST',
credentials : 'include',
body : JSON.stringify(selected)
});
async function loadDoc(){
const url = api(`document/${id}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
doc.positions = await resp.json();
error = null;
doc = await resp.json();
error = null;
} else {
error = await resp.text();
}
@@ -109,6 +91,28 @@
pdfDisabled = false;
}
async function update(path,newValue){
const parts = path.split('.');
if (parts.length<1) return false;
let data = newValue;
while (parts.length > 0){
const inner = data;
data = {};
data[parts.pop()] = inner;
}
try {
const url = api(`document/${doc.id}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
return resp.ok;
} catch (err){
return false;
}
}
onMount(loadDoc);
</script>
@@ -207,6 +211,12 @@
{/if}
</td>
</tr>
<tr>
<th>{t('create_new_object',{object:t('succeeding_document')})}:</th>
<td>
<TypeSelector caption={t('choose_type')} onSelect={createSuccessorDoc} />
</td>
</tr>
</tbody>
</table>
</fieldset>