Subversion Repositories HomeAutomation

Rev

Rev 2192 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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