Subversion Repositories HomeAutomation

Rev

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

Rev 2106 Rev 2111
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;
-
 
7
 
6
 
8
    /* Function to update values of sliders based on new server data */
7
    /* Function to update values of sliders based on new server data */
9
    function handleServerData(jsonData)
8
    function handleServerData(jsonData)
10
    {
9
    {
11
      var list = [];
10
      var list = [];
-
 
11
 
-
 
12
      pageInstance.pageContentElement.empty();
-
 
13
      pageInstance.pagePhoneCallsElement = $("#page-phonecalls-template").tmpl().appendTo(pageInstance.pageContentElement);
12
 
14
   
13
      /* Loop through all */
15
      /* Loop through all */
14
      jQuery.each(jsonData.results, function(timestamp, data)
16
      jQuery.each(jsonData, function(timestamp, data)
15
      {
17
      {
16
        var data = JSON.parse(data);
18
        var data = JSON.parse(data);
17
        var found = false;
19
        var found = false;
18
 
20
 
19
        jQuery.each(pageInstance.aliases, function(n, alias)
21
        jQuery.each(pageInstance.aliases, function(n, alias)
20
        {
22
        {
21
          if (data.module === alias)
23
          if (data.module === alias)
22
          {
24
          {
23
            found = true;
25
            found = true;
24
            return false; // break
26
            return false; // break
25
          }
27
          }
26
        });
28
        });
27
 
29
 
28
        if (!found)
30
        if (!found)
29
        {
31
        {
30
          return true; // continue
32
          return true; // continue
31
        }
-
 
32
 
-
 
33
        if (!data.timestamp)
-
 
34
        {
-
 
35
          data.timestamp = timestamp; // Workaround for older lists
-
 
36
        }
33
        }
37
 
34
 
38
        var d = new Date(data.timestamp * 1000);
35
        var d = new Date(data.timestamp * 1000);
39
        data.time = d.toLocaleString();
36
        data.time = d.toUTCString();
40
 
37
 
41
        if (data.direction === "in" && pageInstance.inText)
38
        if (data.direction === "in" && pageInstance.inText)
42
        {
39
        {
43
          data.directionText = pageInstance.inText;
40
          data.directionText = pageInstance.inText;
44
        }
41
        }
45
        else if (data.direction === "out" && pageInstance.outText)
42
        else if (data.direction === "out" && pageInstance.outText)
46
        {
43
        {
47
          data.directionText = pageInstance.outText;
44
          data.directionText = pageInstance.outText;
48
        }
45
        }
49
        else
46
        else
50
        {
47
        {
51
          data.directionText = data.direction;
48
          data.directionText = data.direction;
Line 55... Line 52...
55
      });
52
      });
56
 
53
 
57
      list.sort(function(a, b)
54
      list.sort(function(a, b)
58
      {
55
      {
59
        return b.timestamp - a.timestamp;
56
        return b.timestamp - a.timestamp;
60
      });
57
      });
61
 
-
 
62
      if (list.length > 0 && pageInstance.lastPhoneCallTimestamp === list[0].timestamp)
-
 
63
      {
-
 
64
        return; // Do not update if no change
-
 
65
      }
-
 
66
 
-
 
67
      pageInstance.pageContentElement.empty();
-
 
68
      pageInstance.pagePhoneCallsElement = $("#page-phonecalls-template").tmpl().appendTo(pageInstance.pageContentElement);
-
 
69
 
-
 
70
      pageInstance.lastPhoneCallTimestamp = list[0].timestamp;
-
 
71
 
58
 
72
      var count = 0;
59
      var count = 0;
73
 
60
 
74
      jQuery.each(list, function(n, item)
61
      jQuery.each(list, function(n, item)
75
      {
62
      {
76
        if (count >= pageInstance.limit)
63
        if (count >= pageInstance.limit)
77
        {
64
        {
78
          return false;
65
          return false;
79
        }
66
        }
80
       
67
       
81
        $("#page-phonecalls-item-template").tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
68
        $("#page-phonecalls-item-template").tmpl(item).appendTo(pageInstance.pageContentElement.find("ul"));
82
 
69
 
83
        count++;
70
        count++;
84
      });
71
      });
85
 
72
 
86
      pageInstance.pagePhoneCallsElement.trigger("create");
73
      pageInstance.pagePhoneCallsElement.trigger("create");
87
 
-
 
88
      var timestamp = getServerTimestamp() / 1000;
-
 
89
 
-
 
90
      if (list.length > 0 && list[0].direction == "in" && list[0].timestamp + 10 > timestamp)
-
 
91
      {
-
 
92
        /* Pause polling timer */
-
 
93
        clearInterval(pageInstance.pollTimer);
-
 
94
        pageInstance.pollTimer = null;
-
 
95
 
-
 
96
        openDialog("Event", pageInstance.inText + " " + list[0].number + ".<br/>" + list[0].names.toString(), 15000, function()
-
 
97
        {
-
 
98
          pageInstance.pollTimer = setInterval(requestServerData, 4000);
-
 
99
        });
-
 
100
      }
-
 
101
    }
74
    }
102
 
75
 
103
   
76
   
104
    /* Function to request new values from the server */
77
    /* Function to request new values from the server */
105
    function requestServerData()
78
    function requestServerData()
106
    {
79
    {
107
      sendCommand("Storage_ListParametersRaw PhoneCalls", handleServerData);
80
      sendCommand("JSON.stringify(Storage_ListParametersNative('PhoneCalls'));", handleServerData);
108
    }
81
    }
109
   
82
   
110
   
83
   
111
    /* Request the initial value from the server */
84
    /* Request the initial value from the server */
112
    requestServerData();
85
    requestServerData();