Subversion Repositories HomeAutomation

Rev

Rev 2154 | 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.timeago.js"></script>
  14.     <script src="jquery.mobile-1.1.1.min.js"></script>
  15.     <script src="jquery.tmpl.min.js"></script>
  16.  
  17.     <style>
  18.     <?php
  19.       foreach ($pages as $page)
  20.       {
  21.         include("pages/" . $page . "/style.css");
  22.       }
  23.     ?>
  24.  
  25.       .ui-li-heading {
  26.         white-space: normal;
  27.       }
  28.     </style>
  29.  
  30.     <?php
  31.       foreach ($pages as $page)
  32.       {
  33.         include("pages/" . $page . "/template.html");
  34.       }
  35.     ?>
  36.  
  37.     <script id="page-template" type="text/x-jquery-tmpl" data-enhance="false">
  38.       <div id="page-${name}" data-role="page" data-theme="a" id="page-{name}">
  39.         <div data-id="PersistentFooter" data-role="header" data-position="fixed" data-tap-toggle="false">
  40.           <div data-role="navbar">
  41.             <ul class="navbar-container"></ul>
  42.           </div>
  43.         </div>
  44.         <div data-role="content"></div>
  45.       </div>
  46.     </script>
  47.  
  48.     <script id="pagelink-template" type="text/x-jquery-tmpl" data-enhance="false">
  49.       <span>
  50.         <a href="#" data-role="button">${title}</a>
  51.       </span>
  52.     </script>
  53.  
  54.     <script>
  55.       $.mobile.ignoreContentEnabled = true;
  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;
  66.  
  67.       var commandActive = false;
  68.       var commandQueue = [];
  69.  
  70.       function sendCommand(command, callback)
  71.       {
  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.           {
  82.             handleCommandResponse(true, jsonData, callback);
  83.           }).error(function()
  84.           {
  85.             handleCommandResponse(false, {}, callback);
  86.           });
  87.         }
  88.       }
  89.  
  90.       function handleCommandResponse(success, jsonData, callback)
  91.       {
  92.         commandActive = false;
  93.  
  94.         if (commandQueue.length > 0)
  95.         {
  96.           var commandItem = commandQueue.shift();
  97.  
  98.           sendCommand(commandItem.command, commandItem.callback);
  99.         }
  100.  
  101.         if (success)
  102.         {
  103.           if (callback)
  104.           {
  105.             callback(jsonData);
  106.           }
  107.         }
  108.         else
  109.         {
  110.           console.log("command failed!");
  111.         }
  112.       }
  113.     </script>
  114.  
  115.     <script>
  116.       var pages = {};
  117.  
  118.     <?php
  119.       foreach ($pages as $page)
  120.       {
  121.         include("pages/" . $page . "/script.js");
  122.       }
  123.     ?>
  124.     </script>
  125.  
  126.     <script>
  127.  
  128.       var aliasNames = <?php echo json_encode($aliasNames); ?>;
  129.       var pageConfigurations = <?php echo json_encode($pageConfiguration); ?>;
  130.       var pageInstances = { };
  131.       var serverTimeOffset = 0;
  132.  
  133.       function getServerTimestamp()
  134.       {
  135.         return ((new Date()).getTime()) - serverTimeOffset
  136.       }
  137.  
  138.       $(document).ready(function(event)
  139.       {
  140.         sendCommand("(new Date()).getTime();", function(timestamp)
  141.         {
  142.           serverTimeOffset = ((new Date()).getTime()) - parseInt(timestamp, 10);
  143.         });
  144.  
  145.         jQuery.each(pageConfigurations, function(n, configuration)
  146.         {
  147.           var pageName = configuration.page + "_" + n;
  148.  
  149.           pageInstances[pageName] = configuration;
  150.  
  151.           pageInstances[pageName].name = pageName;
  152.  
  153.           pageInstances[pageName].pageElement = $("#page-template").tmpl(pageInstances[pageName]).appendTo($("body")).page();
  154.           pageInstances[pageName].pageContentElement = pageInstances[pageName].pageElement.find(":jqmData(role=content)");
  155.  
  156.           if (pages[configuration.page] && pages[configuration.page].init)
  157.           {
  158.             pages[configuration.page].init(pageInstances[pageName]);
  159.           }
  160.         });
  161.  
  162.        
  163.         jQuery.each(pageInstances, function(pageName, pageInstance)
  164.         {
  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.         {
  185.           var nextpage = $(this).nextAll(":jqmData(role=page)");
  186.  
  187.           if (nextpage.length > 0)
  188.           {
  189.             $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true });
  190.           }
  191.           else
  192.           {
  193.             nextpage = $(":jqmData(role=page)");
  194.  
  195.             $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true });
  196.           }
  197.         });
  198.        
  199.         $(".ui-page").on("swiperight", function()
  200.         {
  201.           var prevpage = $(this).prevAll(":jqmData(role=page)");
  202.  
  203.           if (prevpage.length > 0)
  204.           {
  205.             $.mobile.changePage("#" + prevpage[0].id, { transition: "none", reverse: true, changeHash: true });
  206.           }
  207.           else
  208.           {
  209.             prevpage = $(":jqmData(role=page)");
  210.  
  211.             $.mobile.changePage("#" + prevpage[prevpage.length - 1].id, { transition: "none", reverse: true, changeHash: true });
  212.           }
  213.         });*/
  214.  
  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.  
  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.           }
  245.         });
  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.  
  254.       });
  255.  
  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.  
  317.     </script>
  318.   </head>
  319.  
  320.   <body>
  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.  
  329.   </body>
  330. </html>
  331.