Rev 2111 | Rev 2193 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2111 | Rev 2192 | ||
|---|---|---|---|
| Line 3... | Line 3... | ||
| 3 | init: function(pageInstance) |
3 | init: function(pageInstance) |
| 4 | { |
4 | { |
| 5 | /* List to keep referenses to all the different slider elements */ |
5 | /* List to keep referenses to all the different slider elements */ |
| 6 | pageInstance.pageInfoElements = {}; |
6 | pageInstance.pageInfoElements = {}; |
| 7 | 7 | ||
| - | 8 | this.pageshow = function(arg) { |
|
| - | 9 | /* Request the initial value from the server */ |
|
| - | 10 | requestServerData(); |
|
| - | 11 | ||
| - | 12 | /* Set timer for continious polling of the current values */ |
|
| - | 13 | pageInstance.pollTimer = setInterval(requestServerData, 2000); |
|
| - | 14 | } |
|
| - | 15 | ||
| - | 16 | this.pagehide = function(arg) { |
|
| - | 17 | clearInterval(pageInstance.pollTimer); |
|
| - | 18 | } |
|
| 8 | 19 | ||
| 9 | /* Function to update values of sliders based on new server data */ |
20 | /* Function to update values of sliders based on new server data */ |
| 10 | function handleServerData(jsonData) |
21 | function handleServerData(jsonData) |
| 11 | { |
22 | { |
| 12 | /* Loop through all results */ |
23 | /* Loop through all results */ |
| Line 23... | Line 34... | ||
| 23 | /* Loop through all values */ |
34 | /* Loop through all values */ |
| 24 | jQuery.each(data, function(name, value) |
35 | jQuery.each(data, function(name, value) |
| 25 | { |
36 | { |
| 26 | /* Check if the value is simple or complex */ |
37 | /* Check if the value is simple or complex */ |
| 27 | if (typeof value.value == "string") |
38 | if (typeof value.value == "string") |
| 28 | { |
39 | { |
| 29 | text += "<b>" + name + "</b> : <i>" + value.value + "</i><br/>"; |
40 | text += "<b>" + name + "</b> : <i>" + value.value + "</i><br/>"; |
| 30 | } |
41 | } |
| 31 | else |
42 | else |
| 32 | { |
43 | { |
| 33 | text += "<b>" + name + "</b><br/>"; |
44 | text += "<b>" + name + "</b><br/>"; |
| 34 | jQuery.each(value.value, function(name2, value2) |
45 | jQuery.each(value.value, function(name2, value2) |
| 35 | { |
46 | { |
| 36 | text += " " + name2 + " : <i>" + value2 + "</i><br/>"; |
47 | text += " " + name2 + " : <i>" + value2 + "</i><br/>"; |
| 37 | }); |
48 | }); |
| 38 | } |
49 | } |
| 39 | }); |
50 | }); |
| 40 | 51 | ||
| 41 | /* If no values were found print a nice text */ |
52 | /* If no values were found print a nice text */ |
| 42 | if (text.length == 0) |
53 | if (text.length == 0) |
| 43 | { |
54 | { |
| 44 | text = "<i>No data available</i>"; |
55 | text = "<i>No data available</i>"; |
| 45 | } |
56 | } |
| 46 | 57 | ||
| 47 | var name = alias; |
58 | var name = alias; |
| 48 | 59 | ||
| 49 | if (aliasNames[alias]) |
60 | if (aliasNames[alias]) |
| 50 | { |
61 | { |
| 51 | name = aliasNames[alias]; |
62 | name = aliasNames[alias]; |
| 52 | } |
63 | } |
| 53 | 64 | ||
| 54 | /* Add the title */ |
65 | /* Add the title */ |
| 55 | text = "<h3>" + name + "</h3>" + text + "<br/>"; |
66 | text = "<h3>" + name + "</h3>" + text + "<br/>"; |
| 56 | 67 | ||
| 57 | /* Update the element markup */ |
68 | /* Update the element markup */ |
| 58 | pageInstance.pageInfoElements[alias].html(text); |
69 | pageInstance.pageInfoElements[alias].html(text); |
| 59 | } |
70 | } |
| 60 | }); |
71 | }); |
| 61 | } |
72 | } |
| 62 | 73 | ||
| 63 | 74 | ||
| 64 | /* Function to request new values from the server */ |
75 | /* Function to request new values from the server */ |
| 65 | function requestServerData() |
76 | function requestServerData() |
| 66 | { |
77 | { |
| 67 | sendCommand("JSON.stringify(Module_GetLastDataNative('" + pageInstance.aliases.join("','") + "'));", handleServerData); |
78 | sendCommand("JSON.stringify(Module_GetLastDataNative('" + pageInstance.aliases.join("','") + "'));", handleServerData); |
| 68 | } |
79 | } |
| 69 | 80 | ||
| 70 | 81 | ||
| 71 | /* Loop through all the aliases and create sliders */ |
82 | /* Loop through all the aliases and create sliders */ |
| 72 | jQuery.each(pageInstance.aliases, function(n, alias) |
83 | jQuery.each(pageInstance.aliases, function(n, alias) |
| 73 | { |
84 | { |
| 74 | var name = alias; |
85 | var name = alias; |
| 75 | 86 | ||
| Line 79... | Line 90... | ||
| 79 | } |
90 | } |
| 80 | 91 | ||
| 81 | /* Create the info HTML from the template and add it to the DOM */ |
92 | /* Create the info HTML from the template and add it to the DOM */ |
| 82 | pageInstance.pageInfoElements[alias] = $("#page-info-template").tmpl({ alias: alias, name: name }).appendTo(pageInstance.pageContentElement).trigger("create"); |
93 | pageInstance.pageInfoElements[alias] = $("#page-info-template").tmpl({ alias: alias, name: name }).appendTo(pageInstance.pageContentElement).trigger("create"); |
| 83 | }); |
94 | }); |
| 84 | - | ||
| 85 | - | ||
| 86 | /* Request the initial value from the server */ |
- | |
| 87 | requestServerData(); |
- | |
| 88 | - | ||
| 89 | - | ||
| 90 | /* Set timer for continious polling of the current values */ |
- | |
| 91 | pageInstance.pollTimer = setInterval(requestServerData, 4000); |
- | |
| 92 | } |
95 | } |
| 93 | }; |
96 | }; |