Mercurial > xmpp-account-manager
diff vcard.js @ 27:02b5bceeca64
Add vCard birthday support, and only include complete values in the vCard.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 23 Dec 2018 16:51:53 +0100 |
parents | d9da5c3e305d |
children | 9ba4f8cc32f1 |
line wrap: on
line diff
--- a/vcard.js +++ b/vcard.js @@ -2,8 +2,9 @@ function initVCard(connection) { const vcard_access = document.getElementById('vcard-access'); - const vcard_fullname = document.getElementById('vcard-fullname'); + const vcard_fn = document.getElementById('vcard-fn'); const vcard_email = document.getElementById('vcard-email'); + const vcard_bday = document.getElementById('vcard-bday'); const spinner_img = document.getElementById('vcard-spinner'); const access_spinner_img = document.getElementById('vcard-access-spinner'); @@ -27,36 +28,46 @@ function initVCard(connection) { vcard_data.fn = parseXPathText(vcard, './vcard4:fn/vcard4:text'); vcard_data.email = parseXPathText(vcard, './vcard4:email/vcard4:text'); + vcard_data.bday = parseXPathText(vcard, './vcard4:bday/vcard4:date'); - vcard_fullname.value = vcard_data.fn; - vcard_fullname.disabled = false; + vcard_fn.value = vcard_data.fn; + vcard_fn.disabled = false; vcard_email.value = vcard_data.email; vcard_email.disabled = false; + vcard_bday.value = vcard_data.bday; + vcard_bday.disabled = false; hideSpinner(spinner_img); } function onVCard4RetrievalError(string) { console.log('Failed to retrieve vCard4: ' + string); - vcard_fullname.disabled = false; + vcard_fn.disabled = false; vcard_email.disabled = false; + vcard_bday.disabled = false; hideSpinner(spinner_img); } function setVCard4() { // TODO: avoid overriding fields we don’t understand. const iq = $iq({type: 'set'}) - .c('vcard', {xmlns: 'urn:ietf:params:xml:ns:vcard-4.0'}) - .c('fn') - .c('text').t(vcard_fullname.value).up().up() - .c('email') - .c('text').t(vcard_email.value).up().up() + .c('vcard', {xmlns: 'urn:ietf:params:xml:ns:vcard-4.0'}); + if (vcard_fn.value) + iq.c('fn') + .c('text').t(vcard_fn.value).up().up(); + if (vcard_email.value) + iq.c('email') + .c('text').t(vcard_email.value).up().up(); + if (vcard_bday.value) + iq.c('bday') + .c('date').t(vcard_bday.value).up().up(); connection.sendIQ(iq, onVCard4Changed, onVCard4ChangeError.bind(null, 'coucou')); displaySpinner(spinner_img); } - vcard_fullname.addEventListener('blur', setVCard4); + vcard_fn.addEventListener('blur', setVCard4); vcard_email.addEventListener('blur', setVCard4); + vcard_bday.addEventListener('change', setVCard4); function onVCard4Changed(result_iq) {