Rev 2196 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2196 | Rev 2208 | ||
|---|---|---|---|
| Line 17... | Line 17... | ||
| 17 | 17 | ||
| 18 | /* Function to update values of switches based on new server data */ |
18 | /* Function to update values of switches based on new server data */ |
| 19 | function handleServerData(jsonData) |
19 | function handleServerData(jsonData) |
| 20 | { |
20 | { |
| 21 | /* Loop through all results */ |
21 | /* Loop through all results */ |
| 22 | jQuery.each(jsonData, function( |
22 | jQuery.each(jsonData, function(alias, data) |
| 23 | { |
23 | { |
| 24 | /* Only do something if we know the device and have a value */ |
24 | /* Only do something if we know the device and have a value */ |
| 25 | if (pageInstance.pageSwitchElements[ |
25 | if (pageInstance.pageSwitchElements[alias] && data.State && data.State.value && data.State.timestamp) |
| 26 | { |
26 | { |
| 27 | /* Enable the switch if it was disabled by default */ |
27 | /* Enable the switch if it was disabled by default */ |
| 28 | pageInstance.pageSwitchElements[ |
28 | pageInstance.pageSwitchElements[alias].find("select").slider("enable"); |
| 29 | /* Update the slider with the new value */ |
29 | /* Update the slider with the new value */ |
| 30 | pageInstance.pageSwitchElements[ |
30 | pageInstance.pageSwitchElements[alias].find("select").val(data.State.value.toLowerCase()).slider("refresh"); |
| 31 | 31 | ||
| 32 | var date = new Date(data.timestamp*1000); |
32 | var date = new Date(data.State.timestamp*1000); |
| 33 | //pageInstance.pageSwitchElements[device].find(":jqmData(id=page-irdevice-timestamp-"+device+")").text(date.toDateString()+", "+date.toLocaleTimeString()); |
33 | //pageInstance.pageSwitchElements[device].find(":jqmData(id=page-irdevice-timestamp-"+device+")").text(date.toDateString()+", "+date.toLocaleTimeString()); |
| 34 | pageInstance.pageSwitchElements[ |
34 | pageInstance.pageSwitchElements[alias].find(":jqmData(id=page-irdevice-timestamp-"+alias+")").text(jQuery.timeago(date)); |
| 35 | } |
35 | } |
| 36 | }); |
36 | }); |
| 37 | } |
37 | } |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | /* Function to request new values from the server */ |
40 | /* Function to request new values from the server */ |
| 41 | function requestServerData() |
41 | function requestServerData() |
| 42 | { |
42 | { |
| 43 | sendCommand("JSON.stringify( |
43 | sendCommand("JSON.stringify(Module_GetLastDataNative('" + pageInstance.aliases.join("','") + "'));", handleServerData); |
| 44 | } |
44 | } |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | /* Loop through all the devices and create switches */ |
47 | /* Loop through all the devices and create switches */ |
| 48 | jQuery.each(pageInstance. |
48 | jQuery.each(pageInstance.aliases, function(n, alias) |
| 49 | { |
49 | { |
| 50 | var name = |
50 | var name = alias; |
| 51 | 51 | ||
| 52 | if (aliasNames[ |
52 | if (aliasNames[alias]) |
| 53 | { |
53 | { |
| 54 | name = aliasNames[ |
54 | name = aliasNames[alias]; |
| 55 | } |
55 | } |
| 56 | 56 | ||
| 57 | /* Create the slider HTML from the template and add it to the DOM */ |
57 | /* Create the slider HTML from the template and add it to the DOM */ |
| 58 | pageInstance.pageSwitchElements[ |
58 | pageInstance.pageSwitchElements[alias] = $("#page-irdevicestate-template").tmpl({ device: alias, name: name }).appendTo(pageInstance.pageContentElement).trigger("create"); |
| 59 | 59 | ||
| 60 | /* Before we have any value it should be disabled */ |
60 | /* Before we have any value it should be disabled */ |
| 61 | pageInstance.pageSwitchElements[ |
61 | pageInstance.pageSwitchElements[alias].find("select").slider("disable"); |
| 62 | }); |
62 | }); |
| 63 | } |
63 | } |
| 64 | }; |
64 | }; |
| 65 | 65 | ||