Subversion Repositories HomeAutomation

Rev

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