diff util.js @ 30:9ba4f8cc32f1

Display the returned error in the title of the spinner.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 23 Dec 2018 17:15:38 +0100
parents d9da5c3e305d
children b15e1581c3d4
line wrap: on
line diff
--- a/util.js
+++ b/util.js
@@ -53,10 +53,25 @@ function configurePEPField(node, key, va
                         .up();
 }
 
+function parseErrorIq(iq) {
+    // TODO: actually check that it is the first one.
+    const error = iq.firstChild;
+    if (error.namespaceURI !== 'jabber:client' || error.localName !== 'error')
+        return null;
+    const condition = error.firstChild;
+    if (condition.namespaceURI !== 'urn:ietf:params:xml:ns:xmpp-stanzas')
+        return null;
+    const text = error.lastChild;
+    if (text.namespaceURI !== 'urn:ietf:params:xml:ns:xmpp-stanzas' || text.localName !== 'text')
+        return null;
+    return [condition.localName, text.textContent];
+}
+
 function displaySpinner(spinner) {
     if ('timeoutid' in spinner.dataset)
         clearTimeout(spinner.dataset.timeoutid);
     spinner.src = 'spinner.svg';
+    spinner.title = '';
     spinner.hidden = false;
 }
 
@@ -64,16 +79,18 @@ function spinnerOk(spinner) {
     if ('timeoutid' in spinner.dataset)
         clearTimeout(spinner.dataset.timeoutid);
     spinner.src = 'ok.svg';
+    spinner.title = '';
     spinner.hidden = false;
     spinner.dataset.timeoutid = setTimeout(function () {
         spinner.hidden = true;
     }, 1000);
 }
 
-function spinnerError(spinner) {
+function spinnerError(spinner, title) {
     if ('timeoutid' in spinner.dataset)
         clearTimeout(spinner.dataset.timeoutid);
     spinner.src = 'error.svg';
+    spinner.title = title ? title : '';
     spinner.hidden = false;
 }