Subversion Repositories HomeAutomation

Rev

Rev 2195 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
2195 linlun 1
 
2
pages.Power = {
3
  init: function(pageInstance)
4
  {
5
    this.pageshow = function(arg) {
6
    /* Request the initial value from the server */
7
      requestServerData();
8
      /* Set timer for continious polling of the current values */
9
      pageInstance.pollTimer = setInterval(reloadImage, 60000);
10
      pageInstance.pollTimer2 = setInterval(requestServerData, 2000);
2196 linlun 11
      reloadImage();
2195 linlun 12
    }
13
 
14
    this.pagehide = function(arg) {
15
      clearInterval(pageInstance.pollTimer);
16
      clearInterval(pageInstance.pollTimer2);
17
    }
18
 
19
 
20
    /* List to keep referenses to all the different slider elements */
21
    pageInstance.pagePowerElements = {};
22
 
23
    /* Function to update values based on new server data */
24
    function handleServerData(jsonData)
25
    {
26
      var g1,g2,g3;
27
      /* Loop through all results */
28
      jQuery.each(jsonData, function(alias, data)
29
      {
30
      /* Loop through all values */
31
      jQuery.each(data, function(name, value)
32
      {
33
        if (name == "Power")
34
        {
35
        g1 = value.value;
36
        }
37
        if (name == "Power32")
38
        {
39
        g2 = value.value;
40
        }
41
        if (name == "EnergySum")
42
        {
43
        g3 = value.value;
44
        }
45
      });
46
      });
47
      pageInstance.pageInputElements["grid"].html($("#page-Power-grid-template").tmpl({ grid1: "Power:  "+g1, grid2: "Power32:  "+g2,grid3: "EnergySum:  "+g3}));
48
    }
49
 
50
    /* Function to request new values from the server */
51
    function requestServerData()
52
    {
53
      sendCommand("JSON.stringify(Module_GetLastDataNative('" + pageInstance.alias + "'));", handleServerData);
54
    }
55
 
56
    function reloadImage()
57
    {
58
    pageInstance.pageImageElements["bild"].find("img").attr('src', pageInstance.picture + '?' + Math.random());
59
    }
60
 
61
    var name = pageInstance.alias;
62
 
63
    if (aliasNames[pageInstance.alias])
64
    {
65
      name = aliasNames[pageInstance.alias];
66
    }
67
 
68
    /* Create the Power HTML from the template and add it to the DOM */
69
 
70
    pageInstance.pageInputElements = {};
71
    pageInstance.pageImageElements = {};
72
 
73
 
74
    pageInstance.pageImageElements["bild"] = $("#page-Power-image-template").tmpl({url: pageInstance.picture}).appendTo(pageInstance.pageContentElement).trigger("create");
75
 
76
    pageInstance.pageInputElements["grid"] = $("#page-Power-grid-template").tmpl({ grid1: "Power:  ", grid2: "Power32:  ",grid3: "EnergySum:  "}).appendTo(pageInstance.pageContentElement).trigger("create");
77
 
78
  }
79
 };
80