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