OpenSource Projekt-Management-Software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

72 lines
2.3 KiB

<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
const router = useTinyRouter();
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 = await fetch(url,{
credentials:'include',
method: 'POST',
body: JSON.stringify(data)
});
if (resp.ok){
router.navigate(`/document?company_id=${doc.company.id}`);
} else {
error = await resp.text();
}
}
onMount(loadDoc);
</script>
{#if error}
<span class="error">{error}</span>
{/if}
<fieldset>
<legend>{t('customer_email')} / {t('subject')}</legend>
<input type="text" bind:value={email} />
<input type="text" bind:value={subject} />
</fieldset>
<fieldset>
<legend>{t('message')}</legend>
<textarea bind:value={content}></textarea>
</fieldset>
<fieldset>
<legend>{t('actions')}</legend>
<button onclick={() => router.navigate(`/document/${id}/view`)}>{t('abort')}</button>
<button onclick={doSend}>{t('do_send')}</button>
</fieldset>