Subversion Repositories HomeAutomation

Rev

Rev 2196 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. pages.info = {
  3.   init: function(pageInstance)
  4.   {
  5.     /* List to keep referenses to all the different slider elements */
  6.     pageInstance.pageInfoElements = {};
  7.  
  8.     this.pageshow = function(arg) {
  9.     /* Request the initial value from the server */
  10.       requestServerData();
  11.      
  12.       /* Set timer for continious polling of the current values */
  13.       pageInstance.pollTimer = setInterval(requestServerData, 2000);
  14.     }
  15.    
  16.     this.pagehide = function(arg) {
  17.       clearInterval(pageInstance.pollTimer);
  18.     }
  19.    
  20.     /* Function to update values of sliders based on new server data */
  21.     function handleServerData(jsonData)
  22.     {
  23.       /* Loop through all results */
  24.       jQuery.each(jsonData, function(alias, data)
  25.       {
  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.         }
  71.       });
  72.     }
  73.    
  74.    
  75.     /* Function to request new values from the server */
  76.     function requestServerData()
  77.     {
  78.       sendCommand("JSON.stringify(Module_GetLastDataNative('" + pageInstance.aliases.join("','") + "'));", handleServerData);
  79.     }
  80.        
  81.  
  82.     /* Loop through all the aliases and create sliders */
  83.     jQuery.each(pageInstance.aliases, function(n, alias)
  84.     {
  85.       var name = alias;
  86.  
  87.       if (aliasNames[alias])
  88.       {
  89.         name = aliasNames[alias];
  90.       }
  91.    
  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");
  94.     });
  95.   }
  96. };
  97.