Guest User

Untitled

a guest
Mar 29th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {% extends "LljmHomeBundle::layout.html.twig" %}
  2.  
  3.    {% block body %}
  4.  
  5. <script type="text/javascript" >
  6.  
  7.             var vscpConn = null;
  8.  
  9.             // Create a VSCP websocket
  10.             vscpConn = new vscp.Connection();
  11.  
  12.             // Connect to VSCP server
  13.             vscpConn.connect({
  14.  
  15.                 url: settings.url,
  16.                 userName: settings.user,
  17.                 password: settings.password,
  18.                 vscpkey: settings.vscpkey,
  19.                 authdomain: settings.authdomain,
  20.  
  21.                 onSuccess: function( conn ) {
  22.  
  23.                     // Start receiving VSCP events
  24.                         // Initialize canvas
  25.                         // Don't do this without a established connection, because
  26.                         // the button needs the connection object!
  27.  
  28.                         initCanvas();
  29.                     vscpConn.start({
  30.  
  31.  
  32.                         onError: function( conn ) {
  33.                             alert("Couldn't start receiving events.");
  34.                         }
  35.  
  36.                     });
  37.  
  38.                 },
  39.  
  40.                 onError: function( conn ) {
  41.                     alert("Couldn't establish a connection.");
  42.                 },
  43.  
  44.             });
  45.  
  46.  
  47.         // User interface data
  48.         var ui = {
  49.  
  50.             enable: function() {
  51.                 $( "#ui :input" ).attr( "disabled", false );
  52.             },
  53.  
  54.             disable: function() {
  55.                 $( "#ui :input" ).attr( "disabled", true );
  56.             }
  57.         };
  58.  
  59.         function vscpTurnOnEvent(data1, data2, data3) {
  60.  
  61.             ui.disable();
  62.  
  63.             vscpConn.sendEvent({
  64.                 event: new vscp.Event({
  65.                     vscpClass:      vscp.constants.classes.VSCP_CLASS1_CONTROL,
  66.                     vscpType:       vscp.constants.types.VSCP_TYPE_CONTROL_TURNON,
  67.                     vscpPriority:   vscp.constants.priorities.PRIORITY_3_NORMAL,
  68.                     vscpData:       [ data1, data2, data3 ]
  69.                 }),
  70.  
  71.                 onSuccess: function( conn ) {
  72.                     console.info( "TURNON event sent." );
  73.                     ui.enable();
  74.                 },
  75.  
  76.                 onError: function( conn ) {
  77.                     alert( "Failed to send TURNON event." );
  78.                     ui.enable();
  79.                 }
  80.  
  81.             });
  82.  
  83.         }
  84.  
  85.         function vscpTurnOffEvent(data1, data2, data3) {
  86.  
  87.             ui.disable();
  88.  
  89.             vscpConn.sendEvent({
  90.                 event: new vscp.Event({
  91.                     vscpClass:      vscp.constants.classes.VSCP_CLASS1_CONTROL,
  92.                     vscpType:       vscp.constants.types.VSCP_TYPE_CONTROL_TURNOFF,
  93.                     vscpPriority:   vscp.constants.priorities.PRIORITY_3_NORMAL,
  94.                     vscpData:       [ data1, data2, data3 ]
  95.                 }),
  96.  
  97.                 onSuccess: function( conn ) {
  98.                     console.info( "TURNOFF event sent." );
  99.                     ui.enable();
  100.                 },
  101.  
  102.                 onError: function( conn ) {
  103.                     alert( "Failed to send TURNOFF event." );
  104.                     ui.enable();
  105.                 }
  106.  
  107.             });
  108.  
  109.         }
  110.  
  111. </script>
  112.  
  113. <div id="header" class="hero-unit">
  114.   <h1>{{'Light management' | trans }}</h1>
  115.  
  116. </div>
  117.  
  118. {% set buttonTop = 0 %}
  119.  
  120. <style type="text/css">
  121. table{
  122.     width: 20%;
  123.     border: 1px solid black;
  124. }
  125. th, td{
  126.     padding: 10px;
  127.     text-align: left;
  128.     border: 1px solid black;
  129. }
  130. </style>
  131.  
  132. <table>
  133. {% for lightswitch in lightswitches %}
  134.  
  135.  
  136.   <tr>
  137.     <td>{{ lightswitch.zonename | trans }}</td>
  138.     <td>{{ lightswitch.subzonename | trans }}</td>
  139.     <td><button onclick="vscpTurnOnEvent(0, {{ lightswitch.zoneid }}, {{ lightswitch.subzoneid }})">ON </button></td>
  140.     <td><button onclick="vscpTurnOffEvent(0, {{ lightswitch.zoneid }}, {{ lightswitch.subzoneid }})">OFF</button></td>
  141.     <td>
  142.  
  143.         <canvas id="buttonVentilation{{ buttonTop }}" width="50px" height="50px">
  144.             Your browser does not support HTML5 Canvas.
  145.         </canvas>
  146.  
  147.         <script>
  148.  
  149.             function initCanvas() {
  150.  
  151.  
  152.                 // Show background image
  153. //                var backgroundImage = new vscp.widget.Image({
  154. //                    canvasName: "#myCanvas",
  155. //                    url: "{{ asset('bundles/lljmhome/images/kvarnvillan_plan1_800.jpg') }}"
  156. //                });
  157.  
  158.                 // Create ventilation buttonn
  159.                 button{{ buttonTop }} = new vscp.widget.Button({
  160.                     connection: vscpConn,       // VSCP connection object
  161.                     canvasName: "#buttonVentilation{{ buttonTop }}",    // Canvas id
  162.                     type: 85,                    // Button type
  163.                     scale: 0.3,                 // Scale factor
  164.                     x: 25,                     // x position in the canvas
  165.                     y: 25,                     // y position in the canvas
  166.                     transmitZone: {{ lightswitch.zoneid }},            // Zone where button event will be sent to
  167.                     transmitSubZone: {{ lightswitch.subzoneid }},        // Sub-zone where button event will be sent to
  168.                     receiveZone: {{ lightswitch.zoneid }},             // Zone where state events will come from
  169.                     receiveSubZone: {{ lightswitch.subzoneid }},         // Sub-zone where state events will come from
  170.                     bindToRemoteState: true,    // Button state depends on remote state
  171.                     enable: false               // Disable button by default
  172.                 });
  173.  
  174.                 // The user interface (buttons) make only sense
  175.                 // in case that the event communication is ready
  176.                 button{{ buttonTop }}.setEnabled( true );
  177.  
  178.             };
  179.                                     initCanvas();
  180.  
  181. </script>
  182.     </td>
  183.   </tr>
  184.  
  185. {% set buttonTop = buttonTop + 1 %}
  186.  
  187. {% else %}
  188.     <p>{{ 'No record in this table' | trans }}.</p>
  189. {% endfor %}
  190. </table>
  191.  
  192.           {% endblock %}
Add Comment
Please, Sign In to add comment