Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
2068 runge 1
 
2
pages.info = {
3
  init: function(pageInstance)
4
  {
5
    /* List to keep referenses to all the different slider elements */
6
    pageInstance.pageInfoElements = {};
7
 
8
 
9
    /* Function to update values of sliders based on new server data */
10
    function handleServerData(jsonData)
11
    {
12
      /* Loop through all results */
13
      jQuery.each(jsonData.results, function(alias, data)
14
      {
15
        /* Only do something if we know the alias*/
16
        if (pageInstance.pageInfoElements[alias])
17
        {
18
          /* Clear existing information */
19
          pageInstance.pageInfoElements[alias].empty();
20
 
21
          var text = "";
22
 
23
          /* Loop through all values */
24
          jQuery.each(data, function(name, value)
25
          {
26
            /* Check if the value is simple or complex */
27
            if (typeof value.value == "string")
28
            {
29
              text += "<b>" + name + "</b> : <i>" + value.value + "</i><br/>";
30
            }
31
            else
32
            {
33
              text += "<b>" + name + "</b><br/>";
34
              jQuery.each(value.value, function(name2, value2)
35
              {
36
                text += "&nbsp;&nbsp;" + name2 + " : <i>" + value2 + "</i><br/>";
37
              });
38
            }
39
          });
40
 
41
          /* If no values were found print a nice text */
42
          if (text.length == 0)
43
          {
44
            text = "<i>No data available</i>";
45
          }
46
 
47
          /* Add the title */
2071 runge 48
          text = "<h3>" + alias + "</h3>" + text + "<br/>";
2068 runge 49
 
50
          /* Update the element markup */
51
          pageInstance.pageInfoElements[alias].html(text);
52
        }
53
      });
54
    }
55
 
56
 
57
    /* Function to request new values from the server */
58
    function requestServerData()
59
    {
60
      sendCommand("Module_GetLastDataRaw " + pageInstance.aliases.join(" "), handleServerData);
61
    }
62
 
63
 
64
    /* Loop through all the aliases and create sliders */
65
    jQuery.each(pageInstance.aliases, function(n, alias)
66
    {
67
      /* Create the slider HTML from the template and add it to the DOM */
68
      pageInstance.pageInfoElements[alias] = $("#page-info-template").tmpl({ alias: alias }).appendTo(pageInstance.pageContentElement).trigger("create");
69
    });
70
 
71
 
72
    /* Request the initial value from the server */
73
    requestServerData();
74
 
75
 
76
    /* Set timer for continious polling of the current values */
77
    pageInstance.pollTimer = setInterval(requestServerData, 4000);
78
  }
79
};