Rev 2179 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2093 | runge | 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 | |||
| 2111 | runge | 12 | pageInstance.pageContentElement.empty(); |
| 13 | pageInstance.pagePhoneCallsElement = $("#page-phonecalls-template").tmpl().appendTo(pageInstance.pageContentElement); |
||
| 14 | |||
| 2093 | runge | 15 | /* Loop through all */ |
| 2111 | runge | 16 | jQuery.each(jsonData, function(timestamp, data) |
| 2093 | runge | 17 | { |
| 18 | var data = JSON.parse(data); |
||
| 19 | var found = false; |
||
| 20 | |||
| 2112 | runge | 21 | if (!data.timestamp) |
| 22 | { |
||
| 23 | data.timestamp = timestamp; |
||
| 24 | } |
||
| 25 | |||
| 2093 | runge | 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); |
||
| 2179 | arune | 41 | //data.time = d.toUTCString(); |
| 42 | data.time = d.toDateString()+", "+d.toLocaleTimeString(); |
||
| 2180 | arune | 43 | data.time2 = jQuery.timeago(d); |
| 2093 | runge | 44 | |
| 45 | if (data.direction === "in" && pageInstance.inText) |
||
| 46 | { |
||
| 2102 | runge | 47 | data.directionText = pageInstance.inText; |
| 2093 | runge | 48 | } |
| 49 | else if (data.direction === "out" && pageInstance.outText) |
||
| 50 | { |
||
| 2102 | runge | 51 | data.directionText = pageInstance.outText; |
| 2093 | runge | 52 | } |
| 2102 | runge | 53 | else |
| 54 | { |
||
| 55 | data.directionText = data.direction; |
||
| 56 | } |
||
| 2093 | runge | 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 | |||
| 2140 | linlun | 75 | $("#" + (pageInstance.template ? pageInstance.template : "page-phonecalls-item-template")).tmpl(item).appendTo(pageInstance.pageContentElement.find("ul")); |
| 2093 | runge | 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 | { |
||
| 2111 | runge | 87 | sendCommand("JSON.stringify(Storage_ListParametersNative('PhoneCalls'));", handleServerData); |
| 2093 | runge | 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 */ |
||
| 2097 | runge | 96 | pageInstance.pollTimer = setInterval(requestServerData, 4000); |
| 2093 | runge | 97 | } |
| 98 | }; |