Mercurial > xmpp-account-manager
comparison nickname.js @ 15:3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 22 Dec 2018 18:38:27 +0100 |
parents | aedf80eefc19 |
children | 45bd945c5722 |
comparison
equal
deleted
inserted
replaced
14:962f64b156dd | 15:3eed9fe0bd7c |
---|---|
6 | 6 |
7 const iq = $iq({type: 'get'}) | 7 const iq = $iq({type: 'get'}) |
8 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | 8 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) |
9 .c('items', {node: 'http://jabber.org/protocol/nick'}); | 9 .c('items', {node: 'http://jabber.org/protocol/nick'}); |
10 connection.sendIQ(iq, onNickname, onNicknameRetrievalError.bind(null, 'PubSub query failed.')); | 10 connection.sendIQ(iq, onNickname, onNicknameRetrievalError.bind(null, 'PubSub query failed.')); |
11 spinner_img.hidden = false; | 11 displaySpinner(spinner_img); |
12 | 12 |
13 function onNickname(result_iq) | 13 function onNickname(result_iq) |
14 { | 14 { |
15 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); | 15 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); |
16 if (item == null) | 16 if (item == null) |
17 return onNicknameRetrievalError('no item found.'); | 17 return onNicknameRetrievalError('no item found.'); |
18 const id = item.getAttributeNS(null, 'id'); | 18 const id = item.getAttributeNS(null, 'id'); |
19 const nick = parseXPath(item, './nickname:nick'); | 19 const nick = parseXPath(item, './nickname:nick'); |
20 nick_input.value = nick.textContent; | 20 nick_input.value = nick.textContent; |
21 spinner_img.hidden = true; | 21 hideSpinner(spinner_img); |
22 } | 22 } |
23 | 23 |
24 function onNicknameRetrievalError(string) | 24 function onNicknameRetrievalError(string) |
25 { | 25 { |
26 console.log('Failed to retrieve nickname: ' + string); | 26 console.log('Failed to retrieve nickname: ' + string); |
27 spinner_img.hidden = true; | 27 hideSpinner(spinner_img); |
28 } | 28 } |
29 | 29 |
30 nick_input.addEventListener('blur', function (evt) { | 30 nick_input.addEventListener('blur', function (evt) { |
31 const iq = $iq({type: 'set'}) | 31 const iq = $iq({type: 'set'}) |
32 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | 32 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) |
33 .c('publish', {node: 'http://jabber.org/protocol/nick'}) | 33 .c('publish', {node: 'http://jabber.org/protocol/nick'}) |
34 .c('item', {id: 'current'}) | 34 .c('item', {id: 'current'}) |
35 .c('nick', {xmlns: 'http://jabber.org/protocol/nick'}) | 35 .c('nick', {xmlns: 'http://jabber.org/protocol/nick'}) |
36 .t(nick_input.value); | 36 .t(nick_input.value); |
37 connection.sendIQ(iq, onNicknameChanged, onNicknameChangeError); | 37 connection.sendIQ(iq, onNicknameChanged, onNicknameChangeError); |
38 spinner_img.hidden = false; | 38 displaySpinner(spinner_img); |
39 }); | 39 }); |
40 | 40 |
41 function onNicknameChanged(iq) | 41 function onNicknameChanged(result_iq) |
42 { | 42 { |
43 console.log("onNicknameChanged", iq); | 43 console.log("Nickname successfully changed."); |
44 spinner_img.hidden = true; | 44 spinnerOk(spinner_img); |
45 } | 45 } |
46 | 46 |
47 function onNicknameChangeError(iq) | 47 function onNicknameChangeError(iq) |
48 { | 48 { |
49 console.log("onNicknameChangeError", iq); | 49 console.log("onNicknameChangeError", iq); |
50 spinner_img.hidden = true; | 50 spinnerError(spinner_img); |
51 } | 51 } |
52 } | 52 } |