comparison 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
comparison
equal deleted inserted replaced
26:28967a0bb1b2 27:02b5bceeca64
1 'use strict'; 1 'use strict';
2 2
3 function initVCard(connection) { 3 function initVCard(connection) {
4 const vcard_access = document.getElementById('vcard-access'); 4 const vcard_access = document.getElementById('vcard-access');
5 const vcard_fullname = document.getElementById('vcard-fullname'); 5 const vcard_fn = document.getElementById('vcard-fn');
6 const vcard_email = document.getElementById('vcard-email'); 6 const vcard_email = document.getElementById('vcard-email');
7 const vcard_bday = document.getElementById('vcard-bday');
7 const spinner_img = document.getElementById('vcard-spinner'); 8 const spinner_img = document.getElementById('vcard-spinner');
8 const access_spinner_img = document.getElementById('vcard-access-spinner'); 9 const access_spinner_img = document.getElementById('vcard-access-spinner');
9 10
10 const vcard_data = {}; 11 const vcard_data = {};
11 12
25 if (vcard === null) 26 if (vcard === null)
26 return onVCard4RetrievalError('no vCard4 found, your PubSub node is broken.'); 27 return onVCard4RetrievalError('no vCard4 found, your PubSub node is broken.');
27 28
28 vcard_data.fn = parseXPathText(vcard, './vcard4:fn/vcard4:text'); 29 vcard_data.fn = parseXPathText(vcard, './vcard4:fn/vcard4:text');
29 vcard_data.email = parseXPathText(vcard, './vcard4:email/vcard4:text'); 30 vcard_data.email = parseXPathText(vcard, './vcard4:email/vcard4:text');
31 vcard_data.bday = parseXPathText(vcard, './vcard4:bday/vcard4:date');
30 32
31 vcard_fullname.value = vcard_data.fn; 33 vcard_fn.value = vcard_data.fn;
32 vcard_fullname.disabled = false; 34 vcard_fn.disabled = false;
33 vcard_email.value = vcard_data.email; 35 vcard_email.value = vcard_data.email;
34 vcard_email.disabled = false; 36 vcard_email.disabled = false;
37 vcard_bday.value = vcard_data.bday;
38 vcard_bday.disabled = false;
35 hideSpinner(spinner_img); 39 hideSpinner(spinner_img);
36 } 40 }
37 41
38 function onVCard4RetrievalError(string) 42 function onVCard4RetrievalError(string)
39 { 43 {
40 console.log('Failed to retrieve vCard4: ' + string); 44 console.log('Failed to retrieve vCard4: ' + string);
41 vcard_fullname.disabled = false; 45 vcard_fn.disabled = false;
42 vcard_email.disabled = false; 46 vcard_email.disabled = false;
47 vcard_bday.disabled = false;
43 hideSpinner(spinner_img); 48 hideSpinner(spinner_img);
44 } 49 }
45 50
46 function setVCard4() { 51 function setVCard4() {
47 // TODO: avoid overriding fields we don’t understand. 52 // TODO: avoid overriding fields we don’t understand.
48 const iq = $iq({type: 'set'}) 53 const iq = $iq({type: 'set'})
49 .c('vcard', {xmlns: 'urn:ietf:params:xml:ns:vcard-4.0'}) 54 .c('vcard', {xmlns: 'urn:ietf:params:xml:ns:vcard-4.0'});
50 .c('fn') 55 if (vcard_fn.value)
51 .c('text').t(vcard_fullname.value).up().up() 56 iq.c('fn')
52 .c('email') 57 .c('text').t(vcard_fn.value).up().up();
53 .c('text').t(vcard_email.value).up().up() 58 if (vcard_email.value)
59 iq.c('email')
60 .c('text').t(vcard_email.value).up().up();
61 if (vcard_bday.value)
62 iq.c('bday')
63 .c('date').t(vcard_bday.value).up().up();
54 connection.sendIQ(iq, onVCard4Changed, onVCard4ChangeError.bind(null, 'coucou')); 64 connection.sendIQ(iq, onVCard4Changed, onVCard4ChangeError.bind(null, 'coucou'));
55 displaySpinner(spinner_img); 65 displaySpinner(spinner_img);
56 } 66 }
57 67
58 vcard_fullname.addEventListener('blur', setVCard4); 68 vcard_fn.addEventListener('blur', setVCard4);
59 vcard_email.addEventListener('blur', setVCard4); 69 vcard_email.addEventListener('blur', setVCard4);
70 vcard_bday.addEventListener('change', setVCard4);
60 71
61 function onVCard4Changed(result_iq) 72 function onVCard4Changed(result_iq)
62 { 73 {
63 console.log('Successfully set vCard4.') 74 console.log('Successfully set vCard4.')
64 spinnerOk(spinner_img); 75 spinnerOk(spinner_img);