Subversion Repositories HomeAutomation

Rev

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.         data.time = d.toDateString()+", "+d.toLocaleTimeString();
  43.  
  44.         if (data.direction === "in" && pageInstance.inText)
  45.         {
  46.           data.directionText = pageInstance.inText;
  47.         }
  48.         else if (data.direction === "out" && pageInstance.outText)
  49.         {
  50.           data.directionText = pageInstance.outText;
  51.         }
  52.         else
  53.         {
  54.           data.directionText = data.direction;
  55.         }
  56.  
  57.         list.push(data);
  58.       });
  59.  
  60.       list.sort(function(a, b)
  61.       {
  62.         return b.timestamp - a.timestamp;
  63.       });
  64.  
  65.       var count = 0;
  66.  
  67.       jQuery.each(list, function(n, item)
  68.       {
  69.         if (count >= pageInstance.limit)
  70.         {
  71.           return false;
  72.         }
  73.        
  74.         $("#" + (pageInstance.template ? pageInstance.template : "page-phonecalls-item-template")).tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
  75.  
  76.         count++;
  77.       });
  78.  
  79.       pageInstance.pagePhoneCallsElement.trigger("create");
  80.     }
  81.  
  82.    
  83.     /* Function to request new values from the server */
  84.     function requestServerData()
  85.     {
  86.       sendCommand("JSON.stringify(Storage_ListParametersNative('PhoneCalls'));", handleServerData);
  87.     }
  88.    
  89.    
  90.     /* Request the initial value from the server */
  91.     requestServerData();
  92.    
  93.    
  94.     /* Set timer for continious polling of the current values */
  95.     pageInstance.pollTimer = setInterval(requestServerData, 4000);
  96.   }
  97. };
  98.