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