preparing document submission
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -7,6 +7,49 @@
|
||||
|
||||
let { id } = $props();
|
||||
let error = $state(null);
|
||||
let doc = $state(null);
|
||||
let email = $state(null);
|
||||
let content = $state(null);
|
||||
let subject = $state(null);
|
||||
|
||||
async function loadDoc(){
|
||||
let url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}`;
|
||||
let resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
doc = await resp.json();
|
||||
email = doc.customer.email;
|
||||
subject = t('new_document_from',t(doc.type),doc.company.name,doc.number),
|
||||
error = null;
|
||||
} else {
|
||||
error = await resp.text();
|
||||
return;
|
||||
}
|
||||
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}/settings`;
|
||||
resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
const settings = await resp.json();
|
||||
content = settings.content;
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
|
||||
async function doSend(){
|
||||
var data = {email:email,subject:subject,content:content};
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}/send`;
|
||||
const resp = fetch(url,{
|
||||
credentials:'include',
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
if (resp.ok){
|
||||
router.navigate('/document');
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
|
||||
onMount(loadDoc);
|
||||
</script>
|
||||
|
||||
{#if error}
|
||||
@@ -14,11 +57,15 @@
|
||||
{/if}
|
||||
|
||||
<fieldset>
|
||||
<legend>{t('customer_email')}</legend>
|
||||
<legend>{t('customer_email')} / {t('subject')}</legend>
|
||||
<input type="text" bind:value={email} />
|
||||
<input type="text" bind:value={subject} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('content')}</legend>
|
||||
<legend>{t('message')}</legend>
|
||||
<textarea bind:value={content}></textarea>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('actions')}</legend>
|
||||
<button onclick={doSend}>{t('do_send')}</button>
|
||||
</fieldset>
|
||||
@@ -8,6 +8,7 @@ export async function loadTranslation(lang){
|
||||
}
|
||||
|
||||
export function t(key,...args){
|
||||
if (key === undefined) return "";
|
||||
if (key instanceof Response) key = 'status.'+key.status;
|
||||
let set = translations.values;
|
||||
let keys = key.split('.');
|
||||
|
||||
Reference in New Issue
Block a user