Subversion Repositories HomeAutomation

Rev

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

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