altered contact/add in order to make use of the new contact backend instead of the legacy API
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import {onMount} from 'svelte';
|
||||
|
||||
import {api} from '../urls.svelte.js';
|
||||
import {addr, email, extra, fn, name, org} from '../vcard.js';
|
||||
import {t} from '../translations.svelte.js';
|
||||
|
||||
let {
|
||||
@@ -14,10 +15,40 @@
|
||||
let value = 0;
|
||||
|
||||
async function loadContacts(){
|
||||
const url = api('document/contacts');
|
||||
const url = api('contact/list');
|
||||
const resp = await fetch(url,{ credentials: 'include'});
|
||||
if (resp.ok){
|
||||
contacts = await resp.json();
|
||||
const json = await resp.json();
|
||||
contacts = Object.values(json).map(contact => {
|
||||
contact.ADR = addr(contact.vcard);
|
||||
contact.EMAIL = email(contact.vcard);
|
||||
contact.N = name(contact.vcard);
|
||||
contact.FN = fn(contact.vcard);
|
||||
contact.ORG = org(contact.vcard);
|
||||
const extras = contact.vcard.match(/^X-.*:.+/gm);
|
||||
for (let ex of extras){
|
||||
ex = extra(ex);
|
||||
switch (ex.name){
|
||||
case 'CUSTOMER-NUMBER':
|
||||
contact.customer_number = ex.value;
|
||||
break;
|
||||
case 'TAX-NUMBER':
|
||||
contact.tax_id = ex.value;
|
||||
break;
|
||||
case 'BANK-ACCOUNT':
|
||||
contact.bank_account = ex.value;
|
||||
break;
|
||||
case 'COURT':
|
||||
contact.local_court = ex.value;
|
||||
break;
|
||||
default:
|
||||
console.log(ex);
|
||||
}
|
||||
}
|
||||
delete contact.vcard;
|
||||
console.log(contact);
|
||||
return contact;
|
||||
})
|
||||
} else {
|
||||
message = await resp.text();
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@
|
||||
<span class="symbol {home?'':'inactive'}" onclick={toggleHome}></span>
|
||||
<span class="symbol {work?'':'inactive'}" onclick={toggleWork} ></span>
|
||||
</div>
|
||||
<LineEditor type="span" editable={true} value={address.box} onSet={newVal => onSet(address.box,newVal)} title={t('post_box')} />
|
||||
<LineEditor type="span" editable={true} value={address.ext} onSet={newVal => onSet(address.ext,newVal)} title={t('extended_address')} />
|
||||
<LineEditor type="span" editable={true} value={address.street} onSet={newVal => onSet(address.street,newVal)} title={t('street')} />
|
||||
<LineEditor type="span" editable={true} value={address.code} onSet={newVal => onSet(address.code,newVal)} title={t('post_code')} />
|
||||
<LineEditor type="span" editable={true} value={address.loc} onSet={newVal => onSet(address.loc,newVal)} title={t('locality')} />
|
||||
<LineEditor type="span" editable={true} value={address.region} onSet={newVal => onSet(address.region,newVal)} title={t('region')} />
|
||||
<LineEditor type="span" editable={true} value={address.country} onSet={newVal => onSet(address.country,newVal)} title={t('country')} />
|
||||
<LineEditor type="span" editable={true} value={address.box} onSet={newVal => onSet(address.box,newVal)} title={t('post_box')} />
|
||||
<LineEditor type="span" editable={true} value={address.ext} onSet={newVal => onSet(address.ext,newVal)} title={t('extended_address')} />
|
||||
<LineEditor type="span" editable={true} value={address.street} onSet={newVal => onSet(address.street,newVal)} title={t('street')} />
|
||||
<LineEditor type="span" editable={true} value={address.post_code} onSet={newVal => onSet(address.post_code,newVal)} title={t('post_code')} />
|
||||
<LineEditor type="span" editable={true} value={address.locality} onSet={newVal => onSet(address.locality,newVal)} title={t('locality')} />
|
||||
<LineEditor type="span" editable={true} value={address.region} onSet={newVal => onSet(address.region,newVal)} title={t('region')} />
|
||||
<LineEditor type="span" editable={true} value={address.country} onSet={newVal => onSet(address.country,newVal)} title={t('country')} />
|
||||
</div>
|
||||
@@ -68,9 +68,9 @@
|
||||
if (contact.ADR.locality) addr += contact.ADR.post_code + " "+ contact.ADR.locality + "\n";
|
||||
if (contact.ADR.county) addr += contact.ADR.country+"\n";
|
||||
document.customer.name = addr;
|
||||
document.customer.tax_id = contact['X-TAX-NUMBER'];
|
||||
document.customer.id = contact['X-CUSTOMER-NUMBER'];
|
||||
document.customer.email = contact.EMAIL.val;
|
||||
document.customer.tax_id = contact.tax_id;
|
||||
document.customer.id = contact.customer_number;
|
||||
document.customer.email = contact.EMAIL;
|
||||
}
|
||||
|
||||
async function submit(){
|
||||
|
||||
@@ -14,9 +14,9 @@ export function addr(vcard){
|
||||
adr.box = parts[0];
|
||||
adr.ext = parts[1];
|
||||
adr.street = parts[2];
|
||||
adr.loc = parts[3];
|
||||
adr.locality = parts[3];
|
||||
adr.region = parts[4];
|
||||
adr.code = parts[5];
|
||||
adr.post_code = parts[5];
|
||||
adr.country = parts[6];
|
||||
}
|
||||
return adr;
|
||||
|
||||
Reference in New Issue
Block a user