Subversion Repositories HomeAutomation

Rev

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