Subversion Repositories HomeAutomation

Rev

Rev 2096 | Rev 2102 | 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.results, 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.toLocaleString();
  37.  
  38.         if (data.direction === "in" && pageInstance.inText)
  39.         {
  40.           data.direction = pageInstance.inText;
  41.         }
  42.         else if (data.direction === "out" && pageInstance.outText)
  43.         {
  44.           data.direction = pageInstance.outText;
  45.         }
  46.  
  47.         list.push(data);
  48.       });
  49.  
  50.       list.sort(function(a, b)
  51.       {
  52.         return b.timestamp - a.timestamp;
  53.       });
  54.  
  55.       var count = 0;
  56.  
  57.       jQuery.each(list, function(n, item)
  58.       {
  59.         if (count >= pageInstance.limit)
  60.         {
  61.           return false;
  62.         }
  63.        
  64.         $("#page-phonecalls-item-template").tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
  65.  
  66.         count++;
  67.       });
  68.  
  69.       pageInstance.pagePhoneCallsElement.trigger("create");
  70.     }
  71.  
  72.    
  73.     /* Function to request new values from the server */
  74.     function requestServerData()
  75.     {
  76.       sendCommand("Storage_ListParametersRaw PhoneCalls", handleServerData);
  77.     }
  78.    
  79.    
  80.     /* Request the initial value from the server */
  81.     requestServerData();
  82.    
  83.    
  84.     /* Set timer for continious polling of the current values */
  85.     pageInstance.pollTimer = setInterval(requestServerData, 4000);
  86.   }
  87. };
  88.