Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
2250 englund 1
 
2
pages.graphs = {
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);
11
      reloadImage();
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.pageGraphsElements = {};
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["bilder"].find("img").each(function(){
59
          $(this).attr('src', pageInstance.pictures[$(this).attr('id')] + '?' + Math.random());
60
          //alert("ID" + $(this).id);
61
          });
62
    }
63
 
64
    /*var name = pageInstance.alias;
65
 
66
    if (aliasNames[pageInstance.alias])
67
    {
68
      name = aliasNames[pageInstance.alias];
69
    } */
70
 
71
    /* Create the Power HTML from the template and add it to the DOM */
72
 
73
    //pageInstance.pageInputElements = {};
74
    pageInstance.pageImageElements = {};
75
 
76
    var images = [];
77
 
78
    jQuery.each(pageInstance.pictures, function(n, url) {
79
       images.push({collapsed:!(n==1), url:url, idx:n});
80
    });
81
 
82
    pageInstance.pageImageElements["bilder"] = $("#page-graphs-images-template").tmpl({image: images}).appendTo(pageInstance.pageContentElement).trigger("create");
83
 
84
    //pageInstance.pageInputElements["grid"] = $("#page-Power-grid-template").tmpl({ grid1: "Power:  ", grid2: "Power32:  ",grid3: "EnergySum:  "}).appendTo(pageInstance.pageContentElement).trigger("create");
85
 
86
  }
87
 };
88