Mercurial > xmpp-account-manager
changeset 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 | 28967a0bb1b2 |
children | e6d8095f2c0a |
files | index.xhtml vcard.js |
diffstat | 2 files changed, 26 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/index.xhtml +++ b/index.xhtml @@ -104,7 +104,7 @@ Enter your nickname, so people you know <div class="col-sm-8"> <p> <label>Full name<br/> -<input id="vcard-fullname" disabled=""/></label><br/> +<input id="vcard-fn" disabled=""/></label><br/> Enter your name, so people you know can recognize you. </p> <p> @@ -113,6 +113,10 @@ Enter your name, so people you know can This can be used if you forget your password. </p> <p> +<label>Birthday<br/> +<input id="vcard-bday" type="date" disabled=""/></label> +</p> +<p> <label>Who can see your vCard?<br/> <select id="vcard-access"> <option value="open">Anyone</option>
--- 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) {