Parameter file to store selected audio device
[ampy.git] / html / ampy.js
1 function repportError(errortext) {
2         domError = document.getElementById('errorpannel');
3         domError.innerHTML = errortext;
4         if (domError.style.display != 'block')
5                 domError.style.display = 'block';
6 }
7
8 function repportSuccess() {
9         domError = document.getElementById('errorpannel');
10         if (domError.style.display != 'none')
11                 domError.style.display = 'none';
12 }
13
14 function updatePage(strdata) {
15         try {
16                 data = JSON.parse(strdata);
17         } catch(SyntaxError) {
18                 repportError("Error decoding json");
19                 console.warn("Error decoding json: "+strdata);
20                 return;
21         }
22         errorfound = false;
23         for (key in data) {
24                 value = data[key];
25                 switch(key) {
26                 case 'watts':
27                         document.getElementById('currentpower').innerHTML = value.toFixed(1);
28                         break;
29                 case 'counter':
30                         document.getElementById('totalpower').innerHTML = value.toFixed(5);
31                         break;
32                 case 'error':
33                         repportError(value);
34                         errorfound = true;
35                         break;
36                 }
37         }
38         if (!errorfound)
39                 repportSuccess();
40 }