Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2068 | runge | 1 | |
| 2 | pages.info = { |
||
| 3 | init: function(pageInstance) |
||
| 4 | { |
||
| 5 | /* List to keep referenses to all the different slider elements */ |
||
| 6 | pageInstance.pageInfoElements = {}; |
||
| 7 | |||
| 8 | |||
| 9 | /* Function to update values of sliders based on new server data */ |
||
| 10 | function handleServerData(jsonData) |
||
| 11 | { |
||
| 12 | /* Loop through all results */ |
||
| 13 | jQuery.each(jsonData.results, function(alias, data) |
||
| 14 | { |
||
| 15 | /* Only do something if we know the alias*/ |
||
| 16 | if (pageInstance.pageInfoElements[alias]) |
||
| 17 | { |
||
| 18 | /* Clear existing information */ |
||
| 19 | pageInstance.pageInfoElements[alias].empty(); |
||
| 20 | |||
| 21 | var text = ""; |
||
| 22 | |||
| 23 | /* Loop through all values */ |
||
| 24 | jQuery.each(data, function(name, value) |
||
| 25 | { |
||
| 26 | /* Check if the value is simple or complex */ |
||
| 27 | if (typeof value.value == "string") |
||
| 28 | { |
||
| 29 | text += "<b>" + name + "</b> : <i>" + value.value + "</i><br/>"; |
||
| 30 | } |
||
| 31 | else |
||
| 32 | { |
||
| 33 | text += "<b>" + name + "</b><br/>"; |
||
| 34 | jQuery.each(value.value, function(name2, value2) |
||
| 35 | { |
||
| 36 | text += " " + name2 + " : <i>" + value2 + "</i><br/>"; |
||
| 37 | }); |
||
| 38 | } |
||
| 39 | }); |
||
| 40 | |||
| 41 | /* If no values were found print a nice text */ |
||
| 42 | if (text.length == 0) |
||
| 43 | { |
||
| 44 | text = "<i>No data available</i>"; |
||
| 45 | } |
||
| 46 | |||
| 2080 | runge | 47 | var name = alias; |
| 48 | |||
| 49 | if (aliasNames[alias]) |
||
| 50 | { |
||
| 51 | name = aliasNames[alias]; |
||
| 52 | } |
||
| 53 | |||
| 2068 | runge | 54 | /* Add the title */ |
| 2080 | runge | 55 | text = "<h3>" + name + "</h3>" + text + "<br/>"; |
| 2068 | runge | 56 | |
| 57 | /* Update the element markup */ |
||
| 58 | pageInstance.pageInfoElements[alias].html(text); |
||
| 59 | } |
||
| 60 | }); |
||
| 61 | } |
||
| 62 | |||
| 63 | |||
| 64 | /* Function to request new values from the server */ |
||
| 65 | function requestServerData() |
||
| 66 | { |
||
| 67 | sendCommand("Module_GetLastDataRaw " + pageInstance.aliases.join(" "), handleServerData); |
||
| 68 | } |
||
| 69 | |||
| 70 | |||
| 71 | /* Loop through all the aliases and create sliders */ |
||
| 72 | jQuery.each(pageInstance.aliases, function(n, alias) |
||
| 73 | { |
||
| 2080 | runge | 74 | var name = alias; |
| 75 | |||
| 76 | if (aliasNames[alias]) |
||
| 77 | { |
||
| 78 | name = aliasNames[alias]; |
||
| 79 | } |
||
| 80 | |||
| 2068 | runge | 81 | /* Create the slider HTML from the template and add it to the DOM */ |
| 2080 | runge | 82 | pageInstance.pageInfoElements[alias] = $("#page-info-template").tmpl({ alias: alias, name: name }).appendTo(pageInstance.pageContentElement).trigger("create"); |
| 2068 | runge | 83 | }); |
| 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 | } |
||
| 93 | }; |