Subversion Repositories HomeAutomation

Rev

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