Subversion Repositories HomeAutomation

Rev

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