Cleanup
[ampy.git] / html / ampy.js
index 0b2ae9883a0e942461f6a0f4549cc1182e1f038e..f372214e6ab336d8e6d789b53068e6dd5a77b0f6 100644 (file)
@@ -4,11 +4,13 @@ function repportError(errortext) {
        if (domError.style.display != 'block')
                domError.style.display = 'block';
 }
+
 function repportSuccess() {
        domError = document.getElementById('errorpannel');
        if (domError.style.display != 'none')
                domError.style.display = 'none';
 }
+
 function updatePage(strdata) {
        try {
                data = JSON.parse(strdata);
@@ -17,7 +19,22 @@ function updatePage(strdata) {
                console.warn("Error decoding json: "+strdata);
                return;
        }
-       document.getElementById('currentpower').innerHTML = data.watts.toFixed(1);
-       document.getElementById('totalpower').innerHTML = data.counter.toFixed(5);
-       repportSuccess();
+       errorfound = false;
+       for (key in data) {
+               value = data[key];
+               switch(key) {
+               case 'watts':
+                       document.getElementById('currentpower').innerHTML = value.toFixed(1);
+                       break;
+               case 'counter':
+                       document.getElementById('totalpower').innerHTML = value.toFixed(5);
+                       break;
+               case 'error':
+                       repportError(value);
+                       errorfound = true;
+                       break;
+               }
+       }
+       if (!errorfound)
+               repportSuccess();
 }