Subversion Repositories HomeAutomation

Rev

Rev 2112 | Rev 2140 | 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.         if (!data.timestamp)
  22.         {
  23.           data.timestamp = timestamp;
  24.         }
  25.        
  26.         jQuery.each(pageInstance.aliases, function(n, alias)
  27.         {
  28.           if (data.module === alias)
  29.           {
  30.             found = true;
  31.             return false; // break
  32.           }
  33.         });
  34.  
  35.         if (!found)
  36.         {
  37.           return true; // continue
  38.         }
  39.  
  40.         var d = new Date(data.timestamp * 1000);
  41.         data.time = d.toUTCString();
  42.  
  43.         if (data.direction === "in" && pageInstance.inText)
  44.         {
  45.           data.directionText = pageInstance.inText;
  46.         }
  47.         else if (data.direction === "out" && pageInstance.outText)
  48.         {
  49.           data.directionText = pageInstance.outText;
  50.         }
  51.         else
  52.         {
  53.           data.directionText = data.direction;
  54.         }
  55.  
  56.         list.push(data);
  57.       });
  58.  
  59.       list.sort(function(a, b)
  60.       {
  61.         return b.timestamp - a.timestamp;
  62.       });
  63.  
  64.       var count = 0;
  65.  
  66.       jQuery.each(list, function(n, item)
  67.       {
  68.         if (count >= pageInstance.limit)
  69.         {
  70.           return false;
  71.         }
  72.        
  73.         $("#" + (pageInstance.template ? pageInstance.template : "page-phonecalls-item-template").tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
  74.  
  75.         count++;
  76.       });
  77.  
  78.       pageInstance.pagePhoneCallsElement.trigger("create");
  79.     }
  80.  
  81.    
  82.     /* Function to request new values from the server */
  83.     function requestServerData()
  84.     {
  85.       sendCommand("JSON.stringify(Storage_ListParametersNative('PhoneCalls'));", handleServerData);
  86.     }
  87.    
  88.    
  89.     /* Request the initial value from the server */
  90.     requestServerData();
  91.    
  92.    
  93.     /* Set timer for continious polling of the current values */
  94.     pageInstance.pollTimer = setInterval(requestServerData, 4000);
  95.   }
  96. };
  97.