Subversion Repositories HomeAutomation

Rev

Rev 2096 | Rev 2104 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. <?php
  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>
  15.  
  16.     <style>
  17.     <?php
  18.       foreach ($pages as $page)
  19.       {
  20.         include("pages/" . $page . "/style.css");
  21.       }
  22.     ?>
  23.  
  24.       .ui-li-heading {
  25.         white-space: normal;
  26.       }
  27.     </style>
  28.  
  29.     <?php
  30.       foreach ($pages as $page)
  31.       {
  32.         include("pages/" . $page . "/template.html");
  33.       }
  34.     ?>
  35.  
  36.     <script id="page-template" type="text/x-jquery-tmpl" data-enhance="false">
  37.       <div id="page-${name}" data-role="page" data-theme="a" id="page-{name}">
  38.         <div data-role="header">
  39.           <a href="#home" data-icon="home" data-direction="reverse">Home</a>
  40.           <h1>${title} - Home Automation Control Center</h1>
  41.         </div>
  42.         <div data-role="content"></div>
  43.       </div>
  44.     </script>
  45.  
  46.     <script id="pagelink-template" type="text/x-jquery-tmpl" data-enhance="false">
  47.       <span>
  48.         <a href="#" data-role="button">${title}</a>
  49.       </span>
  50.     </script>
  51.  
  52.     <script>
  53.       $.mobile.ignoreContentEnabled = true;
  54.       $.mobile.transitionFallbacks.pop = "none";
  55.       $.mobile.transitionFallbacks.flip = "none";
  56.       $.mobile.transitionFallbacks.turn = "none";
  57.       $.mobile.transitionFallbacks.flow = "none";
  58.       $.mobile.transitionFallbacks.slidefade = "none";
  59.       $.mobile.transitionFallbacks.slide = "none";
  60.       $.mobile.transitionFallbacks.slideup = "none";
  61.       $.mobile.transitionFallbacks.slidedown = "none";
  62.       $.mobile.defaultPageTransition = "none";
  63.       $.mobile.ajaxEnabled = false;
  64.  
  65.       var commandActive = false;
  66.       var commandQueue = [];
  67.  
  68.       function sendCommand(command, callback)
  69.       {
  70.         if (commandActive)
  71.         {
  72.           commandQueue.push({ command: command, callback: callback });
  73.         }
  74.         else
  75.         {
  76.           commandActive = true;
  77.  
  78.           jQuery.getJSON("backend.php?ajax", { command: command }, function(jsonData)
  79.           {
  80.             commandActive = false;
  81.  
  82.             if (commandQueue.length > 0)
  83.             {
  84.               var commandItem = commandQueue.shift();
  85.  
  86.               sendCommand(commandItem.command, commandItem.callback);
  87.             }
  88.  
  89.             callback(jsonData);
  90.           });
  91.         }
  92.       }
  93.     </script>
  94.  
  95.     <script>
  96.       var pages = {};
  97.  
  98.     <?php
  99.       foreach ($pages as $page)
  100.       {
  101.         include("pages/" . $page . "/script.js");
  102.       }
  103.     ?>
  104.     </script>
  105.  
  106.     <script>
  107.  
  108.       var aliasNames = <?php echo json_encode($aliasNames); ?>;
  109.       var pageConfigurations = <?php echo json_encode($pageConfiguration); ?>;
  110.       var pageInstances = {};
  111.       var serverTimeOffset = 0;
  112.  
  113.       function getServerTimestamp()
  114.       {
  115.         return ((new Date()).getTime()) - serverTimeOffset
  116.       }
  117.  
  118.       $(document).ready(function(event)
  119.       {
  120.         document.location.hash = "";
  121.  
  122.         sendCommand("timestampRaw", function(jsonData)
  123.         {
  124.           serverTimeOffset = ((new Date()).getTime()) - jsonData.timestamp;
  125.         });
  126.  
  127.         jQuery.each(pageConfigurations, function(n, configuration)
  128.         {
  129.           var pageName = configuration.page + "_" + n;
  130.  
  131.           pageInstances[pageName] = configuration;
  132.  
  133.           pageInstances[pageName].name = pageName;
  134.  
  135.           pageInstances[pageName].pageElement = $("#page-template").tmpl(pageInstances[pageName]).appendTo($("body")).page();
  136.           pageInstances[pageName].pageContentElement = pageInstances[pageName].pageElement.find(":jqmData(role=content)");
  137.  
  138.           pageInstances[pageName].pageElement.find(":jqmData(rel=back)").on("click", function(event)
  139.           {
  140.             $.mobile.changePage("#home", { transition: "slide", reverse: true });
  141.             event.preventDefault();
  142.           });
  143.  
  144.           pageInstances[pageName].pageLinkElement = $("#pagelink-template").tmpl(pageInstances[pageName]).appendTo($("#home").find(":jqmData(role=content)")).trigger("create").on("click", function(event)
  145.           {
  146.             $.mobile.changePage("#" + pageInstances[pageName].pageElement.attr("id"), "slide");
  147.             event.preventDefault();
  148.           });
  149.  
  150.  
  151.           if (pages[configuration.page] && pages[configuration.page].init)
  152.           {
  153.             pages[configuration.page].init(pageInstances[pageName]);
  154.           }
  155.         });
  156.  
  157.         $(".ui-page").on("swipeleft", function()
  158.         {
  159.           var nextpage = $(this).nextAll(":jqmData(role=page)");
  160.  
  161.           if (nextpage.length > 0)
  162.           {
  163.             $.mobile.changePage("#" + nextpage[0].id, { transition: "slide", changeHash: true });
  164.           }
  165.         });
  166.        
  167.         $(".ui-page").on("swiperight", function()
  168.         {
  169.           var prevpage = $(this).prevAll(":jqmData(role=page)");
  170.  
  171.           if (prevpage.length > 0)
  172.           {
  173.             $.mobile.changePage("#" + prevpage[0].id, { transition: "slide", reverse: true, changeHash: true });
  174.           }
  175.         });
  176.       });
  177.  
  178.       var dialogCloseTimer = null;
  179.       var dialogCloseCallback = null;
  180.  
  181.       function openDialog(titleText, contentsHtml, autoCloseTimeout, closeCallback)
  182.       {
  183.         closeDialog();
  184.  
  185.         $("#dialog .dialog-title").text(titleText);
  186.         $("#dialog .dialog-contents").html(contentsHtml);
  187.         $("#dialog a").on("click", function(event)
  188.         {
  189.           closeDialog();
  190.           event.preventDefault();
  191.           return false;
  192.         });
  193.      
  194.         dialogCloseCallback = closeCallback;
  195.  
  196.         $.mobile.changePage($("#dialog"), { role: "dialog"});
  197.  
  198.         $("#dialog").dialog({ close: function(event)
  199.         {
  200.           var callback = dialogCloseCallback;
  201.  
  202.           closeDialog();
  203.  
  204.           if (callback)
  205.           {
  206.             callback();
  207.           }
  208.         }});
  209.  
  210.  
  211.         if (autoCloseTimeout)
  212.         {
  213.           dialogCloseTimer = setTimeout(closeDialog, autoCloseTimeout);
  214.         }
  215.       }
  216.  
  217.       function closeDialog()
  218.       {
  219.         if (dialogCloseTimer)
  220.         {
  221.           clearTimeout(dialogCloseTimer);
  222.           dialogCloseTimer = null;
  223.         }
  224.  
  225.         if ($("#dialog").is(":visible"))
  226.         {
  227.           $("#dialog").dialog("close");
  228.  
  229.           if (dialogCloseCallback)
  230.           {
  231.             dialogCloseCallback();
  232.           }
  233.         }
  234.  
  235.         dialogCloseCallback = null;
  236.       }
  237.  
  238.  
  239.     </script>
  240.   </head>
  241.  
  242.   <body>
  243.     <div id="home" data-role="page" data-theme="a">
  244.       <div data-role="header"><h1>Home Automation Control Center</h1></div>
  245.       <div data-role="content"></div>
  246.     </div>
  247.  
  248.     <div data-role="dialog" id="dialog">
  249.       <div data-role="content">
  250.         <h3 class="dialog-title"></h3>
  251.         <p class="dialog-contents"></p>
  252.         <a href="#" data-role="button" data-theme="c">Close</a>
  253.       </div>
  254.     </div>
  255.  
  256.   </body>
  257. </html>
  258.