preparing creation of successor document
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -59,7 +59,6 @@
|
||||
} else {
|
||||
onMount(load);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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'});
|
||||
if (resp.ok){
|
||||
companies = await resp.json();
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
function createDoc(type){
|
||||
router.navigate(`/document/add?company_id=${selected_company.id}&document_type=${type}`)
|
||||
}
|
||||
|
||||
if (company_id) {
|
||||
for (let comp of companies){
|
||||
if (comp.id == company_id){
|
||||
load(comp);
|
||||
break;
|
||||
}
|
||||
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){
|
||||
load(selected_company); // relaod docs
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,29 +49,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
function createDoc(){
|
||||
router.navigate(`/document/add?company_id=${selected_company.id}&document_type=${docType}`)
|
||||
async function loadCompanies(){
|
||||
const url = api('company/list');
|
||||
const resp = await fetch(url,{ credentials: 'include'});
|
||||
if (resp.ok){
|
||||
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`);
|
||||
}
|
||||
|
||||
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){
|
||||
load(selected_company); // relaod docs
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user