Subversion Repositories HomeAutomation

Rev

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