Subversion Repositories HomeAutomation

Rev

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