Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. pages.phonecalls = {
  3.   init: function(pageInstance)
  4.   {
  5.     pageInstance.pagePhoneCallsElement = null;
  6.  
  7.     /* Function to update values of sliders based on new server data */
  8.     function handleServerData(jsonData)
  9.     {
  10.       var list = [];
  11.  
  12.       pageInstance.pageContentElement.empty();
  13.       pageInstance.pagePhoneCallsElement = $("#page-phonecalls-template").tmpl().appendTo(pageInstance.pageContentElement);
  14.    
  15.       /* Loop through all */
  16.       jQuery.each(jsonData, function(timestamp, data)
  17.       {
  18.         var data = JSON.parse(data);
  19.         var found = false;
  20.  
  21.         jQuery.each(pageInstance.aliases, function(n, alias)
  22.         {
  23.           if (data.module === alias)
  24.           {
  25.             found = true;
  26.             return false; // break
  27.           }
  28.         });
  29.  
  30.         if (!found)
  31.         {
  32.           return true; // continue
  33.         }
  34.  
  35.         var d = new Date(data.timestamp * 1000);
  36.         data.time = d.toUTCString();
  37.  
  38.         if (data.direction === "in" && pageInstance.inText)
  39.         {
  40.           data.directionText = pageInstance.inText;
  41.         }
  42.         else if (data.direction === "out" && pageInstance.outText)
  43.         {
  44.           data.directionText = pageInstance.outText;
  45.         }
  46.         else
  47.         {
  48.           data.directionText = data.direction;
  49.         }
  50.  
  51.         list.push(data);
  52.       });
  53.  
  54.       list.sort(function(a, b)
  55.       {
  56.         return b.timestamp - a.timestamp;
  57.       });
  58.  
  59.       var count = 0;
  60.  
  61.       jQuery.each(list, function(n, item)
  62.       {
  63.         if (count >= pageInstance.limit)
  64.         {
  65.           return false;
  66.         }
  67.        
  68.         $("#page-phonecalls-item-template").tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
  69.  
  70.         count++;
  71.       });
  72.  
  73.       pageInstance.pagePhoneCallsElement.trigger("create");
  74.     }
  75.  
  76.    
  77.     /* Function to request new values from the server */
  78.     function requestServerData()
  79.     {
  80.       sendCommand("JSON.stringify(Storage_ListParametersNative('PhoneCalls'));", handleServerData);
  81.     }
  82.    
  83.    
  84.     /* Request the initial value from the server */
  85.     requestServerData();
  86.    
  87.    
  88.     /* Set timer for continious polling of the current values */
  89.     pageInstance.pollTimer = setInterval(requestServerData, 4000);
  90.   }
  91. };
  92.