Subversion Repositories HomeAutomation

Rev

Rev 2097 | Rev 2106 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2097 Rev 2102
Line 1... Line 1...
1
 
1
 
2
pages.phonecalls = {
2
pages.phonecalls = {
3
  init: function(pageInstance)
3
  init: function(pageInstance)
4
  {
4
  {
5
    pageInstance.pagePhoneCallsElement = null;
5
    pageInstance.pagePhoneCallsElement = null;
-
 
6
    pageInstance.lastPhoneCallTimestamp = 0;
6
 
7
 
7
    /* Function to update values of sliders based on new server data */
8
    /* Function to update values of sliders based on new server data */
8
    function handleServerData(jsonData)
9
    function handleServerData(jsonData)
9
    {
10
    {
10
      var list = [];
11
      var list = [];
11
 
-
 
12
      pageInstance.pageContentElement.empty();
-
 
13
      pageInstance.pagePhoneCallsElement = $("#page-phonecalls-template").tmpl().appendTo(pageInstance.pageContentElement);
-
 
14
   
12
 
15
      /* Loop through all */
13
      /* Loop through all */
16
      jQuery.each(jsonData.results, function(timestamp, data)
14
      jQuery.each(jsonData.results, function(timestamp, data)
17
      {
15
      {
18
        var data = JSON.parse(data);
16
        var data = JSON.parse(data);
Line 34... Line 32...
34
 
32
 
35
        var d = new Date(data.timestamp * 1000);
33
        var d = new Date(data.timestamp * 1000);
36
        data.time = d.toLocaleString();
34
        data.time = d.toLocaleString();
37
 
35
 
38
        if (data.direction === "in" && pageInstance.inText)
36
        if (data.direction === "in" && pageInstance.inText)
39
        {
37
        {
40
          data.direction = pageInstance.inText;
38
          data.directionText = pageInstance.inText;
41
        }
39
        }
42
        else if (data.direction === "out" && pageInstance.outText)
40
        else if (data.direction === "out" && pageInstance.outText)
43
        {
41
        {
44
          data.direction = pageInstance.outText;
42
          data.directionText = pageInstance.outText;
-
 
43
        }
-
 
44
        else
-
 
45
        {
-
 
46
          data.directionText = data.direction;
45
        }
47
        }
46
 
48
 
47
        list.push(data);
49
        list.push(data);
48
      });
50
      });
49
 
51
 
50
      list.sort(function(a, b)
52
      list.sort(function(a, b)
51
      {
53
      {
52
        return b.timestamp - a.timestamp;
54
        return b.timestamp - a.timestamp;
53
      });
55
      });
-
 
56
 
-
 
57
      if (list.length > 0 && pageInstance.lastPhoneCallTimestamp === list[0].timestamp)
-
 
58
      {
-
 
59
        return; // Do not update if no change
-
 
60
      }
-
 
61
 
-
 
62
      pageInstance.pageContentElement.empty();
-
 
63
      pageInstance.pagePhoneCallsElement = $("#page-phonecalls-template").tmpl().appendTo(pageInstance.pageContentElement);
-
 
64
 
-
 
65
      pageInstance.lastPhoneCallTimestamp = list[0].timestamp;
54
 
66
 
55
      var count = 0;
67
      var count = 0;
56
 
68
 
57
      jQuery.each(list, function(n, item)
69
      jQuery.each(list, function(n, item)
58
      {
70
      {
59
        if (count >= pageInstance.limit)
71
        if (count >= pageInstance.limit)
60
        {
72
        {
61
          return false;
73
          return false;
62
        }
74
        }
63
       
75
       
64
        $("#page-phonecalls-item-template").tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
76
        $("#page-phonecalls-item-template").tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
65
 
77
 
66
        count++;
78
        count++;
67
      });
79
      });
68
 
80
 
69
      pageInstance.pagePhoneCallsElement.trigger("create");
81
      pageInstance.pagePhoneCallsElement.trigger("create");
-
 
82
 
-
 
83
      var timestamp = getServerTimestamp() / 1000;
-
 
84
 
-
 
85
      if (list.length > 0 && list[0].direction == "in" && list[0].timestamp + 10 > timestamp)
-
 
86
      {
-
 
87
        /* Pause polling timer */
-
 
88
        clearInterval(pageInstance.pollTimer);
-
 
89
        pageInstance.pollTimer = null;
-
 
90
 
-
 
91
        openDialog("Event", pageInstance.inText + " " + list[0].number + ".<br/>" + list[0].names.toString(), 15000, function()
-
 
92
        {
-
 
93
          pageInstance.pollTimer = setInterval(requestServerData, 4000);
-
 
94
        });
-
 
95
      }
70
    }
96
    }
71
 
97
 
72
   
98
   
73
    /* Function to request new values from the server */
99
    /* Function to request new values from the server */
74
    function requestServerData()
100
    function requestServerData()