Mercurial > xmpp-account-manager
view 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 source
'use strict'; function initVCard(connection) { const vcard_access = document.getElementById('vcard-access'); 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'); const vcard_data = {}; const iq = $iq({type: 'get'}) .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) .c('items', {node: 'urn:xmpp:vcard4'}) .c('item', {id: 'current'}); connection.sendIQ(iq, onVCard4, onVCard4RetrievalError.bind(null, 'PubSub query failed.')); displaySpinner(spinner_img); function onVCard4(result_iq) { const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); if (item === null) return onVCard4RetrievalError('no item found.'); const vcard = parseXPath(item, './vcard4:vcard'); if (vcard === null) return onVCard4RetrievalError('no vCard4 found, your PubSub node is broken.'); 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_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_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'}); 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_fn.addEventListener('blur', setVCard4); vcard_email.addEventListener('blur', setVCard4); vcard_bday.addEventListener('change', setVCard4); function onVCard4Changed(result_iq) { console.log('Successfully set vCard4.') spinnerOk(spinner_img); } function onVCard4ChangeError(string) { console.log('Failed to set vCard4: ' + string); spinnerError(spinner_img); } vcard_access.addEventListener('change', function (evt) { const iq = configurePEPField('urn:xmpp:vcard4', 'pubsub#access_model', evt.target.value); connection.sendIQ(iq, onAccessConfigured, onAccessConfigureError.bind(null, 'PubSub configuration failed.')); displaySpinner(access_spinner_img); }); function onAccessConfigured(result_iq) { console.log('Successfully set vCard4 access model.') spinnerOk(access_spinner_img); } function onAccessConfigureError(string) { console.log('Failed to configure vCard4 node: ' + string); spinnerError(access_spinner_img); } }