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

@@ -59,7 +59,6 @@
} else {
onMount(load);
}
</script>
<style>

View File

@@ -99,10 +99,10 @@
<span class="error">{error}</span>
{/if}
{#if docType}
<legend>{t('add_new',docType)}</legend>
<legend>{t('add_object',{object:docType})}</legend>
{/if}
{#if company}
Company: {company.name}
{t('company')}: {company.name}
<fieldset>
<legend>{t('customer')}</legend>
<ContactSelector caption={t('select_customer')} onselect={contactSelected} />
@@ -143,5 +143,5 @@
{t('sender_local_court')}
</label>
</fieldset>
<button onclick={submit}>{t('create_new_document')}</button>
<button onclick={submit}>{t('create_new_object',{object:docType})}</button>
</fieldset>

View File

@@ -12,26 +12,24 @@
let router = useTinyRouter();
let company_id = +router.query.company_id;
let documents = null;
let docType = 0;
let selected_company = null;
async function loadCompanies(){
const url = api('company/list');
const resp = await fetch(url,{ credentials: 'include'});
function createDoc(type){
router.navigate(`/document/add?company_id=${selected_company.id}&document_type=${type}`)
}
async function deleteDoc(ev,doc){
if (confirm(t('really_delete',doc.number))){
const url = api(`document/${doc.id}`);
const resp = await fetch(url,{
credentials: 'include',
method: 'DELETE'
});
if (resp.ok){
companies = await resp.json();
load(selected_company); // relaod docs
} else {
error = await resp.text();
}
if (company_id) {
for (let comp of companies){
if (comp.id == company_id){
load(comp);
break;
}
}
}
}
@@ -51,28 +49,29 @@
}
}
function createDoc(){
router.navigate(`/document/add?company_id=${selected_company.id}&document_type=${docType}`)
}
function show(id){
router.navigate(`/document/${id}/view`);
}
async function deleteDoc(ev,doc){
if (confirm(t('really_delete',doc.number))){
const url = api(`document/${doc.id}`);
const resp = await fetch(url,{
credentials: 'include',
method: 'DELETE'
});
async function loadCompanies(){
const url = api('company/list');
const resp = await fetch(url,{ credentials: 'include'});
if (resp.ok){
load(selected_company); // relaod docs
companies = await resp.json();
} else {
error = await resp.text();
}
if (company_id) {
for (let comp of companies){
if (comp.id == company_id){
load(comp);
break;
}
}
}
}
function show(id){
router.navigate(`/document/${id}/view`);
}
onMount(loadCompanies);
</script>
@@ -100,7 +99,7 @@
<th>{t('state')}</th>
<th>
{t('actions')}
<TypeSelector caption={t('create_new_document')} bind:value={docType} onchange={createDoc} />
<TypeSelector caption={t('create_new_object',{object:t('document')})} onSelect={createDoc} />
</th>
</tr>
</thead>

View File

@@ -6,12 +6,12 @@
let {
caption,
onchange = () => console.log('changed'),
value = $bindable(0)
onSelect = (type) => console.log('changed'),
} = $props();
let message = t('loading');
let types = $state(null);
let value = $state(0);
async function loadTypes(){
const url = api('document/types');
@@ -27,7 +27,7 @@
</script>
{#if types}
<select bind:value onchange={onchange}>
<select bind:value onchange={e => onSelect(value)}>
<option value={0}>{caption}</option>
{#each Object.entries(types) as [id,type]}
<option value={id}>{t('type_'+type)}</option>

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,12 +27,15 @@
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();
doc.positions = await resp.json();
error = null;
} else {
error = await resp.text();
@@ -52,37 +56,15 @@
}
}
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();
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>

View File

@@ -16,6 +16,7 @@
"by": "von",
"cancel": "abbrechen",
"choose_type": "Typ wählen",
"client_id": "Client-ID",
"client_secret": "Client-Geheimnis",
"close_settings": "Einstellungen schließen",
@@ -225,6 +226,7 @@
"subject": "Betreff",
"subtask": "Unteraufgabe",
"subtasks": "Unteraufgaben",
"succeeding_document": "Nachfolge-Dokument",
"sum_of_records": "Summe der ausgewählten Einträge",
"tag_uses": "Verwendung des Tags „{tag}“",
"tags": "Tags",