Subversion Repositories HomeAutomation

Rev

Rev 2193 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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