Subversion Repositories HomeAutomation

Rev

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

  1. pages.irdevicestate = {
  2.   init: function(pageInstance)
  3.   {
  4.     /* List to keep referenses to all the different switch elements */
  5.     pageInstance.pageSwitchElements = {};
  6.  
  7.  
  8.     /* Function to update values of switches based on new server data */
  9.     function handleServerData(jsonData)
  10.     {
  11.       /* Loop through all results */
  12.       jQuery.each(jsonData, function(device, data)
  13.       {
  14.     //$("#debug").html($("#debug").html()+"Got data "+device+" "+data+"<br />\n");
  15.         /* Only do something if we know the device and have a value */
  16.         if (pageInstance.pageSwitchElements[device] && data)
  17.         {
  18.           /* Enable the switch if it was disabled by default */
  19.           pageInstance.pageSwitchElements[device].find("select").slider("enable");
  20.           /* Update the slider with the new value */
  21.           pageInstance.pageSwitchElements[device].find("select").val(data).slider("refresh");
  22.         }
  23.       });
  24.     }
  25.    
  26.    
  27.     /* Function to request new values from the server */
  28.     function requestServerData()
  29.     {
  30.       sendCommand("JSON.stringify(IrDeviceState_GetDataNative('" + pageInstance.devices.join("','") + "'));", handleServerData);
  31.     }
  32.    
  33.    
  34.     /* Loop through all the devices and create switches */
  35.     jQuery.each(pageInstance.devices, function(n, device)
  36.     {
  37.       var name = device;
  38.  
  39.       if (aliasNames[device])
  40.       {
  41.         name = aliasNames[device];
  42.       }
  43.      
  44.       /* Create the slider HTML from the template and add it to the DOM */
  45.       pageInstance.pageSwitchElements[device] = $("#page-irdevicestate-template").tmpl({ device: device, name: name }).appendTo(pageInstance.pageContentElement).trigger("create");
  46.      
  47.       /* Before we have any value it should be disabled */
  48.       pageInstance.pageSwitchElements[device].find("select").slider("disable");
  49.     });
  50.    
  51.    
  52.     /* Request the initial value from the server */
  53.     requestServerData();
  54.    
  55.    
  56.     /* Set timer for continious polling of the current values */
  57.     pageInstance.pollTimer = setInterval(requestServerData, 4000);
  58.   }
  59. };
  60.  
  61.