Subversion Repositories HomeAutomation

Rev

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