Mercurial > xmpp-account-manager
annotate nickname.js @ 35:084202870d76
Add nickname access model configuration.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 23 Dec 2018 21:41:32 +0100 |
parents | 45bd945c5722 |
children | b76146a09e07 |
rev | line source |
---|---|
0 | 1 'use strict'; |
2 | |
3 function initNickname(connection) { | |
4 const nick_input = document.getElementById('nick'); | |
35
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
5 const nick_access = document.getElementById('nick-access'); |
10
e47b9bd55192
Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
6 const spinner_img = document.getElementById('nick-spinner'); |
35
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
7 const access_spinner_img = document.getElementById('nick-access-spinner'); |
0 | 8 |
9 const iq = $iq({type: 'get'}) | |
10 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | |
11 .c('items', {node: 'http://jabber.org/protocol/nick'}); | |
12 connection.sendIQ(iq, onNickname, onNicknameRetrievalError.bind(null, 'PubSub query failed.')); | |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
13 displaySpinner(spinner_img); |
0 | 14 |
15 function onNickname(result_iq) | |
16 { | |
17 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); | |
18 if (item == null) | |
19 return onNicknameRetrievalError('no item found.'); | |
20 const id = item.getAttributeNS(null, 'id'); | |
21 const nick = parseXPath(item, './nickname:nick'); | |
22 nick_input.value = nick.textContent; | |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
23 hideSpinner(spinner_img); |
0 | 24 } |
25 | |
26 function onNicknameRetrievalError(string) | |
27 { | |
28 console.log('Failed to retrieve nickname: ' + string); | |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
29 hideSpinner(spinner_img); |
0 | 30 } |
31 | |
34
45bd945c5722
Change all blur events to change, prevents a stanza when no change occured.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
15
diff
changeset
|
32 nick_input.addEventListener('change', function (evt) { |
0 | 33 const iq = $iq({type: 'set'}) |
34 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | |
35 .c('publish', {node: 'http://jabber.org/protocol/nick'}) | |
36 .c('item', {id: 'current'}) | |
37 .c('nick', {xmlns: 'http://jabber.org/protocol/nick'}) | |
38 .t(nick_input.value); | |
39 connection.sendIQ(iq, onNicknameChanged, onNicknameChangeError); | |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
40 displaySpinner(spinner_img); |
0 | 41 }); |
42 | |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
43 function onNicknameChanged(result_iq) |
0 | 44 { |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
45 console.log("Nickname successfully changed."); |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
46 spinnerOk(spinner_img); |
0 | 47 } |
48 | |
49 function onNicknameChangeError(iq) | |
50 { | |
51 console.log("onNicknameChangeError", iq); | |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
52 spinnerError(spinner_img); |
0 | 53 } |
35
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
54 |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
55 nick_access.addEventListener('change', function (evt) { |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
56 const iq = configurePEPField('http://jabber.org/protocol/nick', 'pubsub#access_model', evt.target.value); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
57 connection.sendIQ(iq, onNicknameConfigured, onNicknameConfigureError); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
58 displaySpinner(access_spinner_img); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
59 }); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
60 |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
61 function onNicknameConfigured(iq) |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
62 { |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
63 console.log('Successfully set nickname access model.') |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
64 spinnerOk(access_spinner_img); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
65 } |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
66 |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
67 function onNicknameConfigureError(iq) |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
68 { |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
69 const string = 'Failed to configure nick node: ' + parseErrorIq(iq); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
70 console.log(string); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
71 spinnerError(access_spinner_img, string); |
084202870d76
Add nickname access model configuration.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
34
diff
changeset
|
72 } |
0 | 73 } |