source: src/main/webapp/list.xhtml@ 24

Last change on this file since 24 was 24, checked in by bart, 4 years ago

Voting requests now contain Offers. Fixed windows whitespace issue. Partiesserver now supports up to 8 parties simultaneously.

File size: 3.3 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3<head>
4<title>Profiles and Domains list</title>
5<link rel="stylesheet" type="text/css" href="css/list.css" />
6
7</head>
8<body>
9 <div class="noscript">
10 <h2 style="color: #ff0000">Seems your browser doesn't support
11 Javascript! Websockets rely on Javascript being enabled. Please
12 enable Javascript and reload this page!</h2>
13 </div>
14 <h1>Currently runnable parties</h1>
15 <div>
16 <table id="partiesTable" class="partiesTable">
17 <tr>
18 <th>Name</th>
19 <th>URI</th>
20 <th>Behaviour</th>
21 <th>Description</th>
22 </tr>
23 <tr>
24 <td>-</td>
25 <td>-</td>
26 <td>-</td>
27 </tr>
28 </table>
29
30 </div>
31</body>
32
33<!-- Script to get/update the list and put it into the table. -->
34<script type="application/javascript">
35
36 <![CDATA[
37 "use strict";
38
39 var ws = null;
40
41 function connect() {
42 var target = 'ws://'+location.host+"/"+location.pathname.split("/")[1]+'/available';
43 if ('WebSocket' in window) {
44 ws = new WebSocket(target);
45 } else if ('MozWebSocket' in window) {
46 ws = new MozWebSocket(target);
47 } else {
48 alert('WebSocket is not supported by this browser. Please use a newer browser');
49 return;
50 }
51 ws.onopen = function () {
52 // whatever.
53 };
54 ws.onmessage = function (event) {
55 //alert(event.data);
56 update(JSON.parse(event.data));
57 };
58 ws.onclose = function (event) {
59 alert('Info: Server closed connection. Code: ' + event.code + (event.reason == "" ? "" : ", Reason: " + event.reason));
60 };
61 }
62
63 /*
64 @param domains a list of GeneralPartyInfo elements.
65 The name can be used to start new instances.
66 */
67 function update(parties) {
68
69 // Find a <table> element with id="myTable":
70 var table = document.getElementById("partiesTable");
71 var oldtablerows=document.querySelectorAll("#partiesTable tr:not(:first-child)");
72 for (var i = 0; i < oldtablerows.length; i++) {
73 oldtablerows[i].parentNode.removeChild(oldtablerows[i]);
74 }
75 for (i in parties) {
76 var party=parties[i];
77 var row = table.insertRow(-1); //-1 = end
78 row.insertCell(0).innerHTML = party['uri'].split('/').pop(); // last element of URI
79 row.insertCell(1).innerHTML = party['uri'];
80 row.insertCell(2).innerHTML = party['capabilities']['behaviours'];
81 row.insertCell(3).innerHTML = party['description'];
82
83 }
84
85 }
86
87 /*
88 This is called when the window DOM is loaded. window.onload runs BEFORE the window is loaded
89 and therefore is too early to remove the noscript message.
90 */
91 document.addEventListener("DOMContentLoaded", function() {
92 // Remove elements with "noscript" class - <noscript> is not allowed in XHTML
93 var noscripts = document.getElementsByClassName("noscript");
94 for (var i = 0; i < noscripts.length; i++) {
95 noscripts[i].parentNode.removeChild(noscripts[i]);
96 }
97 connect();
98
99 }, false);
100 ]]>
101
102</script>
103
104</html>
Note: See TracBrowser for help on using the repository browser.