code cleanup

This commit is contained in:
2025-07-30 09:03:47 +02:00
parent a77efb4e41
commit 631a527a5d
18 changed files with 257 additions and 184 deletions

View File

@@ -1,5 +1,6 @@
<script> <script>
import {onMount} from 'svelte'; import {onMount} from 'svelte';
import { api } from '../urls.svelte.js'; import { api } from '../urls.svelte.js';
import {t} from '../translations.svelte.js'; import {t} from '../translations.svelte.js';

View File

@@ -1,7 +1,10 @@
<script> <script>
import {t} from '../translations.svelte.js'; import {t} from '../translations.svelte.js';
let { task, onSelect = (task) => {} } = $props(); let {
task,
onSelect = (task) => {}
} = $props();
</script> </script>
<div> <div>

View File

@@ -40,8 +40,8 @@
const url = api('markdown/render'); const url = api('markdown/render');
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials: 'include', credentials: 'include',
method: 'POST', method : 'POST',
body: editValue.source body : editValue.source
}); });
editValue.rendered = await resp.text(); editValue.rendered = await resp.text();
} }

View File

@@ -3,9 +3,9 @@
import {t} from '../translations.svelte.js'; import {t} from '../translations.svelte.js';
let { let {
caption = t('select_permission'), caption = t('select_permission'),
selected = $bindable(0), selected = $bindable(0),
onchange = (val) => console.log('changed to',val), onchange = (val) => console.log('changed to',val),
permissions = null permissions = null
} = $props(); } = $props();
@@ -24,4 +24,4 @@
</select> </select>
{:else} {:else}
<span>{message}</span> <span>{message}</span>
{/if} {/if}

View File

@@ -38,7 +38,7 @@
<style> <style>
input{width:100px} input{width:100px}
div{ div{
min-width: 40px; min-width: 40px;
min-height: 20px; min-height: 20px;
} }
.editable:hover{ .editable:hover{

View File

@@ -9,8 +9,8 @@
let company = $state(null); let company = $state(null);
let docType = $state(null); let docType = $state(null);
let error = $state(null); let error = $state(null);
let router = useTinyRouter(); let router = useTinyRouter();
let document = $state({ let document = $state({
type : +router.query.document_type, type : +router.query.document_type,
@@ -18,7 +18,7 @@
name : '' name : ''
}, },
sender : { sender : {
name : 'sender', name : 'sender',
company : +router.query.company_id company : +router.query.company_id
} }
}); });
@@ -45,7 +45,7 @@
const resp = await fetch(url,{ credentials: 'include'}); const resp = await fetch(url,{ credentials: 'include'});
if (resp.ok){ if (resp.ok){
const types = await resp.json(); const types = await resp.json();
docType = t('type_'+types[document.type]); docType = t('type_'+types[document.type]);
} else { } else {
error = await resp.text(); error = await resp.text();
} }
@@ -60,7 +60,7 @@
var addr = ''; var addr = '';
if (contact.ORG) addr += contact.ORG.trim()+"\n"; if (contact.ORG) addr += contact.ORG.trim()+"\n";
if (contact.N) { if (contact.N) {
var name = (contact.N.given+" "+contact.N.family).trim()+"\n"; var name = (contact.N.given+" "+contact.N.family).trim()+"\n";
if (name != addr) addr += name; if (name != addr) addr += name;
} }
if (contact.ADR.street) addr += contact.ADR.street+"\n"; if (contact.ADR.street) addr += contact.ADR.street+"\n";
@@ -75,9 +75,9 @@
async function submit(){ async function submit(){
const url = api('document'); const url = api('document');
const resp = await fetch(url,{ const resp = await fetch(url,{
method: 'POST', method : 'POST',
credentials: 'include', credentials: 'include',
body: JSON.stringify(document) body : JSON.stringify(document)
}); });
if (resp.ok){ if (resp.ok){
const json = await resp.json(); const json = await resp.json();
@@ -144,4 +144,4 @@
</label> </label>
</fieldset> </fieldset>
<button onclick={submit}>{t('create_new_document')}</button> <button onclick={submit}>{t('create_new_document')}</button>
</fieldset> </fieldset>

View File

@@ -1,19 +1,26 @@
<script> <script>
import { t } from '../../translations.svelte.js';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import EstimatedTask from '../../Components/EstimatedTask.svelte';
let { company_id, onSelect = (task) => {} } = $props();
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import EstimatedTask from '../../Components/EstimatedTask.svelte';
let {
company_id,
onSelect = (task) => {}
} = $props();
let error = $state(null);
let projects = $state(null); let projects = $state(null);
let error = $state(null);
async function loadItems(){ async function loadItems(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/task/estimated_times`; const url = api('task/estimated_times');
let data = { company_id: company_id }; let data = { company_id: company_id };
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials:'include', credentials: 'include',
method: 'POST', method : 'POST',
body: JSON.stringify(data) body : JSON.stringify(data)
}); });
if (resp.ok){ if (resp.ok){
projects = await resp.json(); projects = await resp.json();
@@ -53,4 +60,4 @@
</fieldset> </fieldset>
{/each} {/each}
{/if} {/if}
</div> </div>

View File

@@ -1,20 +1,27 @@
<script> <script>
import { t } from '../../translations.svelte.js';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import Item from '../../Components/Item.svelte';
let { company_id, onSelect = (item) => {} } = $props(); import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import Item from '../../Components/Item.svelte';
let {
company_id,
onSelect = (item) => {}
} = $props();
let items = $state(null); let items = $state(null);
let error = $state(null); let error = $state(null);
async function loadItems(){ async function loadItems(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/items/list`; const url = api('items/list');
let data = { company_id: company_id }; let data = { company_id: company_id };
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials:'include', credentials: 'include',
method: 'POST', method : 'POST',
body: JSON.stringify(data) body : JSON.stringify(data)
}); });
if (resp.ok){ if (resp.ok){
items = await resp.json(); items = await resp.json();
@@ -37,4 +44,4 @@
<Item item={item} onclick={() => onSelect(item)} /> <Item item={item} onclick={() => onSelect(item)} />
{/each} {/each}
{/if} {/if}
</div> </div>

View File

@@ -1,21 +1,24 @@
<script> <script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js'; import { api } from '../../urls.svelte.js';
import TypeSelector from './TypeSelector.svelte'; import { t } from '../../translations.svelte.js';
import TypeSelector from './TypeSelector.svelte';
let error = null; let error = null;
let companies = {}; let companies = {};
let documents = null; let company_id = +router.query.company_id;
let documents = null;
let router = useTinyRouter();
let docType = 0;
let selected_company = null; let selected_company = null;
let router = useTinyRouter();
let company_id = +router.query.company_id;
let docType = 0;
async function loadCompanies(){ async function loadCompanies(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/company/list`; const url = api('company/list');
const resp = await fetch(url,{ credentials: 'include'}); const resp = await fetch(url,{ credentials: 'include'});
if (resp.ok){ if (resp.ok){
companies = await resp.json(); companies = await resp.json();
@@ -37,7 +40,7 @@
async function load(company){ async function load(company){
router.navigate(`/document?company_id=${company.id}`); router.navigate(`/document?company_id=${company.id}`);
selected_company = company; selected_company = company;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/list`; const url = api('document/list');
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials: 'include', credentials: 'include',
method: 'POST', method: 'POST',
@@ -60,7 +63,7 @@
async function deleteDoc(ev,doc){ async function deleteDoc(ev,doc){
if (confirm(t('really_delete',doc.number))){ if (confirm(t('really_delete',doc.number))){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}`; const url = api(`document/${doc.id}`;
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials: 'include', credentials: 'include',
method: 'DELETE' method: 'DELETE'
@@ -122,4 +125,4 @@
</tbody> </tbody>
</table> </table>
{/if} {/if}
</fieldset> </fieldset>

View File

@@ -1,10 +1,19 @@
<script> <script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { onMount } from 'svelte';
import LineEditor from '../../Components/LineEditor.svelte'; import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte'; import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import PriceEditor from '../../Components/PriceEditor.svelte'; import PriceEditor from '../../Components/PriceEditor.svelte';
var { currency, editable, pos = $bindable(null), submit = (key,newVal) => {}, movePos = (number,step) => {}, drop = (number) => {} } = $props();
var {
currency,
drop = (number) => {},
editable,
movePos = (number,step) => {},
pos = $bindable(null),
submit = (key,newVal) => {}
} = $props();
let prefix = `pos.${pos.number}` let prefix = `pos.${pos.number}`
function moveup(){ function moveup(){

View File

@@ -1,26 +1,33 @@
<script> <script>
import Position from './Position.svelte'; import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
var { document = $bindable(null), submit = (key,newVal) => {}, error = $bindable(null) } = $props(); import { api } from '../../urls.svelte-js';
import { t } from '../../translations.svelte.js';
import Position from './Position.svelte';
var {
document = $bindable(null),
error = $bindable(null)
submit = (key,newVal) => {},
} = $props();
let editable = $derived(document.state == 1); let editable = $derived(document.state == 1);
async function updatePositions(resp){ async function updatePositions(resp){
let json = await resp.json(); let json = await resp.json();
document.positions = {}; document.positions = {};
error = null;
setTimeout(() => document.positions = json,100) setTimeout(() => document.positions = json,100)
error = null;
} }
async function movePos(number,step){ async function movePos(number,step){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${document.id}/position`; const url = api(`document/${document.id}/position`;
const resp = await fetch(url,{ const resp = await fetch(url,{
method: 'PATCH', method : 'PATCH',
credentials:'include', credentials: 'include',
body:JSON.stringify({position:number,move:step}) body : JSON.stringify({position:number,move:step})
}); });
if (resp.ok){ if (resp.ok){
updatePositions(resp); updatePositions(resp);
@@ -32,11 +39,11 @@
async function drop(number){ async function drop(number){
let confirmed = confirm(t('confirm_deletion').replace('{pos}',document.positions[number].item)); let confirmed = confirm(t('confirm_deletion').replace('{pos}',document.positions[number].item));
if (!confirmed) return; if (!confirmed) return;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${document.id}/position`; const url = api(`document/${document.id}/position`;
const resp = await fetch(url,{ const resp = await fetch(url,{
method: 'DELETE', method : 'DELETE',
credentials:'include', credentials: 'include',
body:JSON.stringify({position:number}) body : JSON.stringify({position:number})
}); });
if (resp.ok){ if (resp.ok){
updatePositions(resp); updatePositions(resp);

View File

@@ -1,10 +1,15 @@
<script> <script>
import { t } from '../../translations.svelte.js'; import { t } from '../../translations.svelte.js';
import EstimateList from './EstimateList.svelte';
import ItemList from './ItemList.svelte';
import TimeList from './TimeList.svelte';
let { close = () => {}, doc = $bindable({}), onSelect = (item) => {} } = $props(); import EstimateList from './EstimateList.svelte';
import ItemList from './ItemList.svelte';
import TimeList from './TimeList.svelte';
let {
close = () => {},
doc = $bindable({}),
onSelect = (item) => {}
} = $props();
let source = $state(0); let source = $state(0);
@@ -15,52 +20,52 @@
function estimateSelected(estimate){ function estimateSelected(estimate){
select({ select({
item_code:t('estimated_time'), item_code : t('estimated_time'),
title:estimate.name, title : estimate.name,
description:estimate.description.source, description : estimate.description.source,
amount:estimate.estimated_time, amount : estimate.estimated_time,
unit:t('hours') unit : t('hours')
}); });
} }
function itemSelected(item){ function itemSelected(item){
select({ select({
item_code:item.code, item_code : item.code,
title:item.name, title : item.name,
description:item.description.source, description : item.description.source,
amount:1, amount : 1,
unit:item.unit, unit : item.unit,
unit_price:item.unit_price, unit_price : item.unit_price,
tax:item.tax tax : item.tax
}); });
} }
function timeSelected(time){ function timeSelected(time){
select({ select({
item_code:t('timetrack'), item_code : t('timetrack'),
title:time.subject, title : time.subject,
description:time.description.source, description : time.description.source,
amount:time.duration, amount : time.duration,
unit:t('hours'), unit : t('hours'),
time_id:time.id time_id : time.id
}); });
} }
</script> </script>
<style> <style>
div{ div{
position: fixed; position : fixed;
top: 0; top : 0;
bottom: 20px; bottom : 20px;
left: 0; left : 0;
right: 0; right : 0;
padding: 10px; padding : 10px;
overflow: auto; overflow : auto;
} }
span{ span{
position: sticky; position : sticky;
top: 0; top : 0;
} }
</style> </style>

View File

@@ -1,34 +1,35 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
const router = useTinyRouter(); import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
let { id } = $props(); let content = $state(null);
let error = $state(null); let doc = $state(null);
let doc = $state(null); let email = $state(null);
let email = $state(null); let error = $state(null);
let content = $state(null); const router = useTinyRouter();
let subject = $state(null); let subject = $state(null);
let { id } = $props();
async function loadDoc(){ async function loadDoc(){
let url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}`; let url = api(`document/${id}`);
let resp = await fetch(url,{credentials:'include'}); let resp = await fetch(url,{credentials:'include'});
if (resp.ok){ if (resp.ok){
doc = await resp.json(); doc = await resp.json();
email = doc.customer.email; email = doc.customer.email;
subject = t('new_document_from',t(doc.type),doc.company.name,doc.number), subject = t('new_document_from',t(doc.type),doc.company.name,doc.number),
error = null; error = null;
} else { } else {
error = await resp.text(); error = await resp.text();
return; return;
} }
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}/settings`; url = api(`document/${id}/settings`);
resp = await fetch(url,{credentials:'include'}); resp = await fetch(url,{credentials:'include'});
if (resp.ok){ if (resp.ok){
const settings = await resp.json(); const settings = await resp.json();
content = settings.content; content = settings.content;
} else { } else {
error = await resp.text(); error = await resp.text();
} }
@@ -36,11 +37,11 @@
async function doSend(){ async function doSend(){
var data = {email:email,subject:subject,content:content}; var data = {email:email,subject:subject,content:content};
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}/send`; const url = api(`document/${id}/send`);
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials:'include', credentials : 'include',
method: 'POST', method : 'POST',
body: JSON.stringify(data) body : JSON.stringify(data)
}); });
if (resp.ok){ if (resp.ok){
router.navigate(`/document?company_id=${doc.company.id}`); router.navigate(`/document?company_id=${doc.company.id}`);

View File

@@ -1,16 +1,23 @@
<script> <script>
import {onMount} from 'svelte'; import {onMount} from 'svelte';
import {t} from '../../translations.svelte.js';
let { caption = t('select_state'), selected = $bindable(0), onchange = (val) => console.log('changed to '+val)} = $props(); import {api} from '../../urls.svelte.js';
import {t} from '../../translations.svelte.js';
let {
caption = t('select_state'),
onchange = (val) => console.log('changed to '+val),
selected = $bindable(0)
} = $props();
let message = $state(t('loading')); let message = $state(t('loading'));
let states = $state(null); let states = $state(null);
async function loadStates(){ async function loadStates(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/states`; const url = api('document/states');
var resp = await fetch(url,{credentials: 'include'}); const resp = await fetch(url,{credentials: 'include'});
if (resp.ok){ if (resp.ok){
states = await resp.json(); states = await resp.json();
} else { } else {
message = await resp.text(); message = await resp.text();
} }

View File

@@ -1,21 +1,30 @@
<script> <script>
import {onMount} from 'svelte'; import {onMount} from 'svelte';
import {t} from '../../translations.svelte.js';
let { caption, company, value = $bindable(0), onchange = () => console.log('changed')} = $props(); import {api} from '../../urls.svelte.js';
let message = t('loading'); import {t} from '../../translations.svelte.js';
let {
caption,
company,
value = $bindable(0),
onchange = () => console.log('changed')
} = $props();
let message = t('loading');
let templates = $state(null); let templates = $state(null);
async function loadTemplates(){ async function loadTemplates(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/templates`; const url = api('document/templates');
var resp = await fetch(url,{ var resp = await fetch(url,{
credentials: 'include', credentials : 'include',
method: 'POST', method : 'POST',
body: JSON.stringify({company:company}) body : JSON.stringify({company:company})
}); });
if (resp.ok){ if (resp.ok){
templates = await resp.json(); templates = await resp.json();
} else { } else {
message = await resp.text(); message = await resp.text();
} }
} }

View File

@@ -1,20 +1,25 @@
<script> <script>
import { t } from '../../translations.svelte.js';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
let { company_id, onSelect = (time) => {} } = $props(); import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
let {
company_id,
onSelect = (time) => {}
} = $props();
let error = $state(null);
let projects = $state(null); let projects = $state(null);
let times = $state(null); let times = $state(null);
let error = $state(null);
async function loadProjects(){ async function loadProjects(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/project/list`; const url = api'project/list');
let data = { company_id: company_id }; let data = { company_id: company_id };
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials:'include', credentials : 'include',
method: 'POST', method : 'POST',
body: JSON.stringify(data) body : JSON.stringify(data)
}); });
if (resp.ok){ if (resp.ok){
projects = await resp.json(); projects = await resp.json();
@@ -24,12 +29,12 @@
} }
async function loadTimes(projectId){ async function loadTimes(projectId){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/times/list`; const url = api('times/list');
let data = { company_id: company_id, project_id: projectId }; let data = { company_id: company_id, project_id: projectId };
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials:'include', credentials : 'include',
method: 'POST', method : 'POST',
body: JSON.stringify(data) body : JSON.stringify(data)
}); });
if (resp.ok){ if (resp.ok){
times = await resp.json(); times = await resp.json();

View File

@@ -1,12 +1,20 @@
<script> <script>
import {onMount} from 'svelte'; import {onMount} from 'svelte';
import {t} from '../../translations.svelte.js';
let { caption, value = $bindable(0), onchange = () => console.log('changed')} = $props(); import {api} from '../../urls.svelte.js';
import {t} from '../../translations.svelte.js';
let {
caption,
onchange = () => console.log('changed'),
value = $bindable(0)
} = $props();
let message = t('loading'); let message = t('loading');
let types = $state(null); let types = $state(null);
async function loadTypes(){ async function loadTypes(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/types`; const url = api('api/document/types');
var resp = await fetch(url,{credentials: 'include'}); var resp = await fetch(url,{credentials: 'include'});
if (resp.ok){ if (resp.ok){
types = await resp.json(); types = await resp.json();

View File

@@ -1,9 +1,11 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import {api} from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import LineEditor from '../../Components/LineEditor.svelte'; import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte'; import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import MultilineEditor from '../../Components/MultilineEditor.svelte'; import MultilineEditor from '../../Components/MultilineEditor.svelte';
@@ -13,23 +15,22 @@
import StateSelector from './StateSelector.svelte'; import StateSelector from './StateSelector.svelte';
import TemplateSelector from './TemplateSelector.svelte'; import TemplateSelector from './TemplateSelector.svelte';
const router = useTinyRouter();
let { id } = $props(); let doc = $state(null);
let error = $state(null); let editable = $derived(doc.state == 1);
let doc = $state(null); let error = $state(null);
let pdfDisabled = $state(false); let { id } = $props();
let sndDisabled = $state(false); let pdfDisabled = $state(false);
let position_select = $state(false); let position_select = $state(false);
const router = useTinyRouter();
let editable = $derived(doc.state == 1); let sndDisabled = $state(false);
async function loadDoc(){ async function loadDoc(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}`; const url = api(`document/${id}`;
const resp = await fetch(url,{credentials:'include'}); const resp = await fetch(url,{credentials:'include'});
if (resp.ok){ if (resp.ok){
doc = await resp.json(); doc = await resp.json();
error = null; error = null;
} else { } else {
error = await resp.text(); error = await resp.text();
@@ -45,8 +46,8 @@
doc.state = newVal; doc.state = newVal;
} else { } else {
const dummy = doc.state; const dummy = doc.state;
doc.state = null; // we need to alter in between, doc.state = null; // we need to alter in between,
doc.state = dummy; // otherwise the state will not be re-set doc.state = dummy; // otherwise the state will not be re-set
} }
} }
@@ -55,16 +56,16 @@
if (parts.length<1) return false; if (parts.length<1) return false;
let data = newValue; let data = newValue;
while (parts.length > 0){ while (parts.length > 0){
const inner = data; const inner = data;
data = {}; data = {};
data[parts.pop()] = inner; data[parts.pop()] = inner;
} }
try { try {
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}`; const url = api(`document/${doc.id}`;
const resp = await fetch(url,{ const resp = await fetch(url,{
credentials:'include', credentials : 'include',
method:'PATCH', method : 'PATCH',
body:JSON.stringify(data) body : JSON.stringify(data)
}); });
return resp.ok; return resp.ok;
} catch (err){ } catch (err){
@@ -73,15 +74,15 @@
} }
async function addPosition(selected){ async function addPosition(selected){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}/position`; const url = api(`document/${doc.id}/position`;
const resp = await fetch(url,{ const resp = await fetch(url,{
method: 'POST', method : 'POST',
credentials:'include', credentials : 'include',
body:JSON.stringify(selected) body : JSON.stringify(selected)
}); });
if (resp.ok){ if (resp.ok){
doc.positions = await resp.json(); doc.positions = await resp.json();
error = null; error = null;
} else { } else {
error = await resp.text(); error = await resp.text();
} }
@@ -90,15 +91,15 @@
async function render(ev){ async function render(ev){
pdfDisabled = true; pdfDisabled = true;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}/pdf`; const url = api(`document/${doc.id}/pdf`;
const resp = await fetch(url,{credentials:'include'}); const resp = await fetch(url,{credentials:'include'});
if (resp.ok){ if (resp.ok){
error = null; error = null;
const blob = await resp.blob(); const blob = await resp.blob();
const parts = resp.headers.get("Content-disposition").split(";"); const parts = resp.headers.get("Content-disposition").split(";");
const filename = parts[1].split('=')[1].split('"').join(''); const filename = parts[1].split('=')[1].split('"').join('');
var fileLink = document.createElement('a'); var fileLink = document.createElement('a');
fileLink.href = URL.createObjectURL(blob); fileLink.href = URL.createObjectURL(blob);
fileLink.download = filename; fileLink.download = filename;
fileLink.click(); fileLink.click();
} else { } else {