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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user