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