Rev 2146 | Rev 2154 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2146 | Rev 2147 | ||
|---|---|---|---|
| 1 | <?php |
1 | <?php |
| 2 | require_once("backend.php"); |
2 | require_once("backend.php"); |
| 3 | require_once("config.php"); |
3 | require_once("config.php"); |
| 4 | ?> |
4 | ?> |
| 5 | <!DOCTYPE HTML> |
5 | <!DOCTYPE HTML> |
| 6 | <html> |
6 | <html> |
| 7 | <head> |
7 | <head> |
| 8 | <meta charset="utf-8"> |
8 | <meta charset="utf-8"> |
| 9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 10 | <title>Home Automation Control Center</title> |
10 | <title>Home Automation Control Center</title> |
| 11 | <link rel="stylesheet" href="jquery.mobile-1.1.1.min.css" /> |
11 | <link rel="stylesheet" href="jquery.mobile-1.1.1.min.css" /> |
| 12 | <script src="jquery-1.7.2.min.js"></script> |
12 | <script src="jquery-1.7.2.min.js"></script> |
| 13 | <script src="jquery.mobile-1.1.1.min.js"></script> |
13 | <script src="jquery.mobile-1.1.1.min.js"></script> |
| 14 | <script src="jquery.tmpl.min.js"></script> |
14 | <script src="jquery.tmpl.min.js"></script> |
| 15 | 15 | ||
| 16 | <style> |
16 | <style> |
| 17 | <?php |
17 | <?php |
| 18 | foreach ($pages as $page) |
18 | foreach ($pages as $page) |
| 19 | { |
19 | { |
| 20 | include("pages/" . $page . "/style.css"); |
20 | include("pages/" . $page . "/style.css"); |
| 21 | } |
21 | } |
| 22 | ?> |
22 | ?> |
| 23 | 23 | ||
| 24 | .ui-li-heading { |
24 | .ui-li-heading { |
| 25 | white-space: normal; |
25 | white-space: normal; |
| 26 | } |
26 | } |
| 27 | </style> |
27 | </style> |
| 28 | 28 | ||
| 29 | <?php |
29 | <?php |
| 30 | foreach ($pages as $page) |
30 | foreach ($pages as $page) |
| 31 | { |
31 | { |
| 32 | include("pages/" . $page . "/template.html"); |
32 | include("pages/" . $page . "/template.html"); |
| 33 | } |
33 | } |
| 34 | ?> |
34 | ?> |
| 35 | 35 | ||
| 36 | <script id="page-template" type="text/x-jquery-tmpl" data-enhance="false"> |
36 | <script id="page-template" type="text/x-jquery-tmpl" data-enhance="false"> |
| 37 | <div id="page-${name}" data-role="page" data-theme="a" id="page-{name}"> |
37 | <div id="page-${name}" data-role="page" data-theme="a" id="page-{name}"> |
| 38 | <div data-id="PersistentFooter" data-role="header" data-position="fixed"> |
38 | <div data-id="PersistentFooter" data-role="header" data-position="fixed" data-tap-toggle="false"> |
| 39 | <div data-role="navbar"> |
39 | <div data-role="navbar"> |
| 40 | <ul class="navbar-container"></ul> |
40 | <ul class="navbar-container"></ul> |
| 41 | </div> |
41 | </div> |
| 42 | </div> |
42 | </div> |
| 43 | <div data-role="content"></div> |
43 | <div data-role="content"></div> |
| 44 | </div> |
44 | </div> |
| 45 | </script> |
45 | </script> |
| 46 | 46 | ||
| 47 | <script id="pagelink-template" type="text/x-jquery-tmpl" data-enhance="false"> |
47 | <script id="pagelink-template" type="text/x-jquery-tmpl" data-enhance="false"> |
| 48 | <span> |
48 | <span> |
| 49 | <a href="#" data-role="button">${title}</a> |
49 | <a href="#" data-role="button">${title}</a> |
| 50 | </span> |
50 | </span> |
| 51 | </script> |
51 | </script> |
| 52 | 52 | ||
| 53 | <script> |
53 | <script> |
| 54 | $.mobile.ignoreContentEnabled = true; |
54 | $.mobile.ignoreContentEnabled = true; |
| 55 | $.mobile.transitionFallbacks.pop = "none"; |
55 | $.mobile.transitionFallbacks.pop = "none"; |
| 56 | $.mobile.transitionFallbacks.flip = "none"; |
56 | $.mobile.transitionFallbacks.flip = "none"; |
| 57 | $.mobile.transitionFallbacks.turn = "none"; |
57 | $.mobile.transitionFallbacks.turn = "none"; |
| 58 | $.mobile.transitionFallbacks.flow = "none"; |
58 | $.mobile.transitionFallbacks.flow = "none"; |
| 59 | $.mobile.transitionFallbacks.slidefade = "none"; |
59 | $.mobile.transitionFallbacks.slidefade = "none"; |
| 60 | $.mobile.transitionFallbacks.slide = "none"; |
60 | $.mobile.transitionFallbacks.slide = "none"; |
| 61 | $.mobile.transitionFallbacks.slideup = "none"; |
61 | $.mobile.transitionFallbacks.slideup = "none"; |
| 62 | $.mobile.transitionFallbacks.slidedown = "none"; |
62 | $.mobile.transitionFallbacks.slidedown = "none"; |
| 63 | $.mobile.defaultPageTransition = "none"; |
63 | $.mobile.defaultPageTransition = "none"; |
| 64 | $.mobile.ajaxEnabled = false; |
64 | $.mobile.ajaxEnabled = false; |
| 65 | 65 | ||
| 66 | var commandActive = false; |
66 | var commandActive = false; |
| 67 | var commandQueue = []; |
67 | var commandQueue = []; |
| 68 | 68 | ||
| 69 | function sendCommand(command, callback) |
69 | function sendCommand(command, callback) |
| 70 | { |
70 | { |
| 71 | if (commandActive) |
71 | if (commandActive) |
| 72 | { |
72 | { |
| 73 | commandQueue.push({ command: command, callback: callback }); |
73 | commandQueue.push({ command: command, callback: callback }); |
| 74 | } |
74 | } |
| 75 | else |
75 | else |
| 76 | { |
76 | { |
| 77 | commandActive = true; |
77 | commandActive = true; |
| 78 | 78 | ||
| 79 | jQuery.getJSON("backend.php?ajax", { command: command }, function(jsonData) |
79 | jQuery.getJSON("backend.php?ajax", { command: command }, function(jsonData) |
| 80 | { |
80 | { |
| 81 | handleCommandResponse(true, jsonData, callback); |
81 | handleCommandResponse(true, jsonData, callback); |
| 82 | }).error(function() |
82 | }).error(function() |
| 83 | { |
83 | { |
| 84 | handleCommandResponse(false, {}, callback); |
84 | handleCommandResponse(false, {}, callback); |
| 85 | }); |
85 | }); |
| 86 | } |
86 | } |
| 87 | } |
87 | } |
| 88 | 88 | ||
| 89 | function handleCommandResponse(success, jsonData, callback) |
89 | function handleCommandResponse(success, jsonData, callback) |
| 90 | { |
90 | { |
| 91 | commandActive = false; |
91 | commandActive = false; |
| 92 | 92 | ||
| 93 | if (commandQueue.length > 0) |
93 | if (commandQueue.length > 0) |
| 94 | { |
94 | { |
| 95 | var commandItem = commandQueue.shift(); |
95 | var commandItem = commandQueue.shift(); |
| 96 | 96 | ||
| 97 | sendCommand(commandItem.command, commandItem.callback); |
97 | sendCommand(commandItem.command, commandItem.callback); |
| 98 | } |
98 | } |
| 99 | 99 | ||
| 100 | if (success) |
100 | if (success) |
| 101 | { |
101 | { |
| 102 | if (callback) |
102 | if (callback) |
| 103 | { |
103 | { |
| 104 | callback(jsonData); |
104 | callback(jsonData); |
| 105 | } |
105 | } |
| 106 | } |
106 | } |
| 107 | else |
107 | else |
| 108 | { |
108 | { |
| 109 | console.log("command failed!"); |
109 | console.log("command failed!"); |
| 110 | } |
110 | } |
| 111 | } |
111 | } |
| 112 | </script> |
112 | </script> |
| 113 | 113 | ||
| 114 | <script> |
114 | <script> |
| 115 | var pages = {}; |
115 | var pages = {}; |
| 116 | 116 | ||
| 117 | <?php |
117 | <?php |
| 118 | foreach ($pages as $page) |
118 | foreach ($pages as $page) |
| 119 | { |
119 | { |
| 120 | include("pages/" . $page . "/script.js"); |
120 | include("pages/" . $page . "/script.js"); |
| 121 | } |
121 | } |
| 122 | ?> |
122 | ?> |
| 123 | </script> |
123 | </script> |
| 124 | 124 | ||
| 125 | <script> |
125 | <script> |
| 126 | 126 | ||
| 127 | var aliasNames = <?php echo json_encode($aliasNames); ?>; |
127 | var aliasNames = <?php echo json_encode($aliasNames); ?>; |
| 128 | var pageConfigurations = <?php echo json_encode($pageConfiguration); ?>; |
128 | var pageConfigurations = <?php echo json_encode($pageConfiguration); ?>; |
| 129 | var pageInstances = { }; |
129 | var pageInstances = { }; |
| 130 | var serverTimeOffset = 0; |
130 | var serverTimeOffset = 0; |
| 131 | 131 | ||
| 132 | function getServerTimestamp() |
132 | function getServerTimestamp() |
| 133 | { |
133 | { |
| 134 | return ((new Date()).getTime()) - serverTimeOffset |
134 | return ((new Date()).getTime()) - serverTimeOffset |
| 135 | } |
135 | } |
| 136 | 136 | ||
| 137 | $(document).ready(function(event) |
137 | $(document).ready(function(event) |
| 138 | { |
138 | { |
| 139 | sendCommand("(new Date()).getTime();", function(timestamp) |
139 | sendCommand("(new Date()).getTime();", function(timestamp) |
| 140 | { |
140 | { |
| 141 | serverTimeOffset = ((new Date()).getTime()) - parseInt(timestamp, 10); |
141 | serverTimeOffset = ((new Date()).getTime()) - parseInt(timestamp, 10); |
| 142 | }); |
142 | }); |
| 143 | 143 | ||
| 144 | jQuery.each(pageConfigurations, function(n, configuration) |
144 | jQuery.each(pageConfigurations, function(n, configuration) |
| 145 | { |
145 | { |
| 146 | var pageName = configuration.page + "_" + n; |
146 | var pageName = configuration.page + "_" + n; |
| 147 | 147 | ||
| 148 | pageInstances[pageName] = configuration; |
148 | pageInstances[pageName] = configuration; |
| 149 | 149 | ||
| 150 | pageInstances[pageName].name = pageName; |
150 | pageInstances[pageName].name = pageName; |
| 151 | 151 | ||
| 152 | pageInstances[pageName].pageElement = $("#page-template").tmpl(pageInstances[pageName]).appendTo($("body")).page(); |
152 | pageInstances[pageName].pageElement = $("#page-template").tmpl(pageInstances[pageName]).appendTo($("body")).page(); |
| 153 | pageInstances[pageName].pageContentElement = pageInstances[pageName].pageElement.find(":jqmData(role=content)"); |
153 | pageInstances[pageName].pageContentElement = pageInstances[pageName].pageElement.find(":jqmData(role=content)"); |
| 154 | 154 | ||
| 155 | if (pages[configuration.page] && pages[configuration.page].init) |
155 | if (pages[configuration.page] && pages[configuration.page].init) |
| 156 | { |
156 | { |
| 157 | pages[configuration.page].init(pageInstances[pageName]); |
157 | pages[configuration.page].init(pageInstances[pageName]); |
| 158 | } |
158 | } |
| 159 | }); |
159 | }); |
| 160 | 160 | ||
| 161 | 161 | ||
| 162 | jQuery.each(pageInstances, function(pageName, pageInstance) |
162 | jQuery.each(pageInstances, function(pageName, pageInstance) |
| 163 | { |
163 | { |
| 164 | var navbarContainerElement = pageInstances[pageName].pageElement.find("ul.navbar-container"); |
164 | var navbarContainerElement = pageInstances[pageName].pageElement.find("ul.navbar-container"); |
| 165 | 165 | ||
| 166 | jQuery.each(pageInstances, function(pageName2, pageInstance2) |
166 | jQuery.each(pageInstances, function(pageName2, pageInstance2) |
| 167 | { |
167 | { |
| 168 | if (pageInstance === pageInstance2) |
168 | if (pageInstance === pageInstance2) |
| 169 | { |
169 | { |
| 170 | $("<li class=''><a href='#page-" + pageName2 + "' class='ui-btn-active ui-state-persist'>" + pageInstance2.title + "</a></li>").appendTo(navbarContainerElement); |
170 | $("<li class=''><a href='#page-" + pageName2 + "' class='ui-btn-active ui-state-persist'>" + pageInstance2.title + "</a></li>").appendTo(navbarContainerElement); |
| 171 | } |
171 | } |
| 172 | else |
172 | else |
| 173 | { |
173 | { |
| 174 | $("<li class=''><a href='#page-" + pageName2 + "'>" + pageInstance2.title + "</a></li>").appendTo(navbarContainerElement); |
174 | $("<li class=''><a href='#page-" + pageName2 + "'>" + pageInstance2.title + "</a></li>").appendTo(navbarContainerElement); |
| 175 | } |
175 | } |
| 176 | }); |
176 | }); |
| 177 | }); |
177 | }); |
| 178 | 178 | ||
| 179 | $(":jqmData(role=header)").navbar(); |
179 | $(":jqmData(role=header)").navbar(); |
| 180 | 180 | ||
| 181 | 181 | ||
| 182 | /*$(".ui-page").on("swipeleft", function() |
182 | /*$(".ui-page").on("swipeleft", function() |
| 183 | { |
183 | { |
| 184 | var nextpage = $(this).nextAll(":jqmData(role=page)"); |
184 | var nextpage = $(this).nextAll(":jqmData(role=page)"); |
| 185 | 185 | ||
| 186 | if (nextpage.length > 0) |
186 | if (nextpage.length > 0) |
| 187 | { |
187 | { |
| 188 | $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true }); |
188 | $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true }); |
| 189 | } |
189 | } |
| 190 | else |
190 | else |
| 191 | { |
191 | { |
| 192 | nextpage = $(":jqmData(role=page)"); |
192 | nextpage = $(":jqmData(role=page)"); |
| 193 | 193 | ||
| 194 | $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true }); |
194 | $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true }); |
| 195 | } |
195 | } |
| 196 | }); |
196 | }); |
| 197 | |
197 | |
| 198 | $(".ui-page").on("swiperight", function() |
198 | $(".ui-page").on("swiperight", function() |
| 199 | { |
199 | { |
| 200 | var prevpage = $(this).prevAll(":jqmData(role=page)"); |
200 | var prevpage = $(this).prevAll(":jqmData(role=page)"); |
| 201 | 201 | ||
| 202 | if (prevpage.length > 0) |
202 | if (prevpage.length > 0) |
| 203 | { |
203 | { |
| 204 | $.mobile.changePage("#" + prevpage[0].id, { transition: "none", reverse: true, changeHash: true }); |
204 | $.mobile.changePage("#" + prevpage[0].id, { transition: "none", reverse: true, changeHash: true }); |
| 205 | } |
205 | } |
| 206 | else |
206 | else |
| 207 | { |
207 | { |
| 208 | prevpage = $(":jqmData(role=page)"); |
208 | prevpage = $(":jqmData(role=page)"); |
| 209 | 209 | ||
| 210 | $.mobile.changePage("#" + prevpage[prevpage.length - 1].id, { transition: "none", reverse: true, changeHash: true }); |
210 | $.mobile.changePage("#" + prevpage[prevpage.length - 1].id, { transition: "none", reverse: true, changeHash: true }); |
| 211 | } |
211 | } |
| 212 | });*/ |
212 | });*/ |
| 213 | 213 | ||
| 214 | $(":jqmData(role=navbar)").delegate("a", "vclick", function(event) |
214 | $(":jqmData(role=navbar)").delegate("a", "vclick", function(event) |
| 215 | { |
215 | { |
| 216 | if(!$(event.target).hasClass("ui-disabled")) |
216 | if(!$(event.target).hasClass("ui-disabled")) |
| 217 | { |
217 | { |
| 218 | $(":jqmData(role=navbar)").find("a").not(".ui-state-persist").removeClass($.mobile.activeBtnClass); |
218 | $(":jqmData(role=navbar)").find("a").not(".ui-state-persist").removeClass($.mobile.activeBtnClass); |
| 219 | $(this).addClass($.mobile.activeBtnClass); |
219 | $(this).addClass($.mobile.activeBtnClass); |
| 220 | } |
220 | } |
| 221 | }); |
221 | }); |
| 222 | 222 | ||
| 223 | if (document.location.hash === "" || document.location.hash === "#") |
223 | if (document.location.hash === "" || document.location.hash === "#") |
| 224 | { |
224 | { |
| 225 | document.location.hash = "#" + $(":jqmData(role=page)").attr("id"); |
225 | document.location.hash = "#" + $(":jqmData(role=page)").attr("id"); |
| 226 | } |
226 | } |
| 227 | 227 | ||
| 228 | $.mobile.changePage($(document.location.hash)); |
228 | $.mobile.changePage($(document.location.hash)); |
| 229 | 229 | ||
| 230 | }); |
230 | }); |
| 231 | 231 | ||
| 232 | var dialogCloseTimer = null; |
232 | var dialogCloseTimer = null; |
| 233 | var dialogCloseCallback = null; |
233 | var dialogCloseCallback = null; |
| 234 | 234 | ||
| 235 | function openDialog(titleText, contentsHtml, autoCloseTimeout, closeCallback) |
235 | function openDialog(titleText, contentsHtml, autoCloseTimeout, closeCallback) |
| 236 | { |
236 | { |
| 237 | closeDialog(); |
237 | closeDialog(); |
| 238 | 238 | ||
| 239 | $("#dialog .dialog-title").text(titleText); |
239 | $("#dialog .dialog-title").text(titleText); |
| 240 | $("#dialog .dialog-contents").html(contentsHtml); |
240 | $("#dialog .dialog-contents").html(contentsHtml); |
| 241 | $("#dialog a").on("click", function(event) |
241 | $("#dialog a").on("click", function(event) |
| 242 | { |
242 | { |
| 243 | closeDialog(); |
243 | closeDialog(); |
| 244 | event.preventDefault(); |
244 | event.preventDefault(); |
| 245 | return false; |
245 | return false; |
| 246 | }); |
246 | }); |
| 247 | 247 | ||
| 248 | dialogCloseCallback = closeCallback; |
248 | dialogCloseCallback = closeCallback; |
| 249 | 249 | ||
| 250 | $.mobile.changePage($("#dialog"), { role: "dialog"}); |
250 | $.mobile.changePage($("#dialog"), { role: "dialog"}); |
| 251 | 251 | ||
| 252 | $("#dialog").dialog({ close: function(event) |
252 | $("#dialog").dialog({ close: function(event) |
| 253 | { |
253 | { |
| 254 | var callback = dialogCloseCallback; |
254 | var callback = dialogCloseCallback; |
| 255 | 255 | ||
| 256 | closeDialog(); |
256 | closeDialog(); |
| 257 | 257 | ||
| 258 | if (callback) |
258 | if (callback) |
| 259 | { |
259 | { |
| 260 | callback(); |
260 | callback(); |
| 261 | } |
261 | } |
| 262 | }}); |
262 | }}); |
| 263 | 263 | ||
| 264 | 264 | ||
| 265 | if (autoCloseTimeout) |
265 | if (autoCloseTimeout) |
| 266 | { |
266 | { |
| 267 | dialogCloseTimer = setTimeout(closeDialog, autoCloseTimeout); |
267 | dialogCloseTimer = setTimeout(closeDialog, autoCloseTimeout); |
| 268 | } |
268 | } |
| 269 | } |
269 | } |
| 270 | 270 | ||
| 271 | function closeDialog() |
271 | function closeDialog() |
| 272 | { |
272 | { |
| 273 | if (dialogCloseTimer) |
273 | if (dialogCloseTimer) |
| 274 | { |
274 | { |
| 275 | clearTimeout(dialogCloseTimer); |
275 | clearTimeout(dialogCloseTimer); |
| 276 | dialogCloseTimer = null; |
276 | dialogCloseTimer = null; |
| 277 | } |
277 | } |
| 278 | 278 | ||
| 279 | if ($("#dialog").is(":visible")) |
279 | if ($("#dialog").is(":visible")) |
| 280 | { |
280 | { |
| 281 | $("#dialog").dialog("close"); |
281 | $("#dialog").dialog("close"); |
| 282 | 282 | ||
| 283 | if (dialogCloseCallback) |
283 | if (dialogCloseCallback) |
| 284 | { |
284 | { |
| 285 | dialogCloseCallback(); |
285 | dialogCloseCallback(); |
| 286 | } |
286 | } |
| 287 | } |
287 | } |
| 288 | 288 | ||
| 289 | dialogCloseCallback = null; |
289 | dialogCloseCallback = null; |
| 290 | } |
290 | } |
| 291 | 291 | ||
| 292 | 292 | ||
| 293 | </script> |
293 | </script> |
| 294 | </head> |
294 | </head> |
| 295 | 295 | ||
| 296 | <body> |
296 | <body> |
| 297 | <div data-role="dialog" id="dialog"> |
297 | <div data-role="dialog" id="dialog"> |
| 298 | <div data-role="content"> |
298 | <div data-role="content"> |
| 299 | <h3 class="dialog-title"></h3> |
299 | <h3 class="dialog-title"></h3> |
| 300 | <p class="dialog-contents"></p> |
300 | <p class="dialog-contents"></p> |
| 301 | <a href="#" data-role="button" data-theme="c">Close</a> |
301 | <a href="#" data-role="button" data-theme="c">Close</a> |
| 302 | </div> |
302 | </div> |
| 303 | </div> |
303 | </div> |
| 304 | 304 | ||
| 305 | </body> |
305 | </body> |
| 306 | </html> |
306 | </html> |
| 307 | 307 | ||