Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  4.     <head>
  5.         <meta charset="utf-8" />
  6.         <title>Hemmet</title>
  7.         <style type="text/css">
  8.             body{
  9.                 zoom: 200%;
  10.                 -moz-transform: scale(2);
  11.                 -moz-transform-origin: 0 0;
  12.             }
  13.         </style>
  14.         <script type="text/javascript">
  15.             var devices = [
  16. { id: 'HallwayFloorOne', title: 'Hallen' },
  17. { id: 'DiningRoomWindows', title: 'Matsalsfönster' },
  18. { id: 'OutsideStair', title: 'Trappen ute' },
  19. { id: 'HallwayFloorTwo', title: 'Hallen uppe' },
  20. { id: 'DiningRoom', title: 'Matsalen'},
  21. { id: 'Driveway', title: 'Uppfarten'}
  22. ];
  23. function createEntry(device) {
  24.     var li = document.createElement('li');
  25.     li.appendChild(createButton('off', function () {
  26.                 performAction(device.id, 'turnoff');
  27.                 }));
  28.     li.appendChild(document.createTextNode(device.title));
  29.     li.appendChild(createButton('on', function () {
  30.                 performAction(device.id, 'turnon');
  31.                 }));
  32.     return li;
  33. }
  34. function performAction(deviceId, command) {
  35.     requestGet('DeviceCommand?device=' + deviceId + '&command=' + command);
  36. }
  37. function requestGet(param){
  38.     var address = 'http://192.168.0.138:1880';
  39.     var httpRequest = new XMLHttpRequest();
  40.     httpRequest.timeout = 500;
  41.     httpRequest.open('GET', address + '/' + param);
  42.     //  httpRequest.open('GET', 'http://192.168.0.138:1880/DeviceCommand?device=' + deviceId + '&command=' + command);
  43.     httpRequest.send(null);
  44. }
  45. function init() {
  46.     var deviceContainer = document.getElementById('deviceList');
  47.     devices.forEach(function (device) {
  48.             var li = createEntry(device);
  49.             deviceContainer.appendChild(li);
  50.             });
  51.     document.getElementById('startBarnkanalen').addEventListener('click', function(){
  52.             requestGet('WebToIr?device=thomson&command=9');
  53.             requestGet('WebToIr?device=tv&command=power');     
  54.             requestGet('WebToIr?command=power&device=tv');  //need two entries to start tv...
  55.             setTimeout(function(){
  56.                 requestGet('WebToIr?device=receiver&command=power');
  57.                 setTimeout(function(){
  58.                     requestGet('WebToIr?device=receiver&command=cbl_sat');
  59.                     },1500);
  60.                 },1500);
  61.             });
  62. }
  63. function createButton(text, func) {
  64.     var button = document.createElement("button");
  65.     button.innerText = text;
  66.     button.addEventListener('click', func)
  67.         return button;
  68. }
  69. document.addEventListener('DOMContentLoaded', init);
  70. </script>
  71. </head>
  72. <body>
  73.     <div id="deviceControl">
  74.         <ul id="deviceList"></ul>
  75.         <ul>
  76.             <button id="startBarnkanalen">Starta barnkanalen</button>
  77.         </ul>
  78.     </div>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement