new-match.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Tables</title>
  5. <link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  7. <body>
  8. <h2>New table</h2>
  9. <div id="new-table-buttons" class="new-table-buttons">
  10. <button type="button" class="pure-button" onclick="newMatch(0)">$</button>
  11. <button type="button" class="pure-button" onclick="newMatch(1)">1</button>
  12. <button type="button" class="pure-button" onclick="newMatch(3)">3</button>
  13. <button type="button" class="pure-button" onclick="newMatch(5)">5</button>
  14. <button type="button" class="pure-button" onclick="newMatch(7)">7</button>
  15. <button type="button" class="pure-button" onclick="newMatch(9)">9</button>
  16. <button type="button" class="pure-button" onclick="newMatch(11)">11</button>
  17. <button type="button" class="pure-button" onclick="newMatch(13)">13</button>
  18. <button type="button" class="pure-button" onclick="newMatch(15)">15</button>
  19. <button type="button" class="pure-button" onclick="newMatch(17)">17</button>
  20. <button type="button" class="pure-button" onclick="newMatch(19)">19</button>
  21. <button type="button" class="pure-button" onclick="newMatch(21)">21</button>
  22. </div>
  23. <div>
  24. <h2>Tables</h2>
  25. <table class="pure-table pure-table-horizontal" id="tables">
  26. <thead>
  27. <tr>
  28. <th></th>
  29. <th>White</th>
  30. <th>Black</th>
  31. <th>Length</th>
  32. <th>Score</th>
  33. </thead>
  34. <tbody>
  35. </tbody>
  36. </table>
  37. </div>
  38. </body>
  39. <script>
  40. function newMatch(limit) {
  41. window.open("/newmatch?limit=" + limit, "_blanck");
  42. }
  43. function fetchTableInfo() {
  44. var xhttp = new XMLHttpRequest();
  45. xhttp.onreadystatechange = function() {
  46. if (this.readyState == 4 && this.status == 200) {
  47. updateTableInfo(JSON.parse(this.responseText));
  48. }
  49. };
  50. xhttp.open("GET", "/tables-info", true);
  51. xhttp.send();
  52. }
  53. function updateTableInfo(tables) {
  54. var table = $("#tables tbody");
  55. table.empty();
  56. tables.forEach(function(t, i) {
  57. console.log(i);
  58. var p;
  59. if (t.BLACK) {
  60. p = "<tr" + (i % 2 == 1 ? "" : " class='pure-table-odd'") + "><td><a href=" + t.URI + ">WATCH</a></td><td>" + t.WHITE +
  61. "</td><td>" + t.BLACK + "</td><td>" +
  62. (t.LIMIT.length != 0 ? t.LIMIT : "money session") + "</td><td>" +
  63. t.SCORE[0] + " : " + t.SCORE[1] + "</td></tr>";
  64. } else {
  65. p = "<tr" + (i % 2 == 1 ? "" : " class='pure-table-odd'") + ">" + "<td></td><td>" + t.WHITE +
  66. "</td><td>" + "<a href=/proposal?table=" + t.URI.replace(/\/[^\/]*\//, "") + ">JOIN</a>" +
  67. "</td><td>" + (t.LIMIT.length != 0 ? t.LIMIT : "money session") + "</td><td>" +
  68. t.SCORE[0] + " : " + t.SCORE[1] + "</td></tr>";
  69. }
  70. table.append(p);
  71. });
  72. }
  73. /*
  74. function updateTableInfo(tables) {
  75. var table = document.getElementById("tables");
  76. table.innerHTML = "";
  77. tables.forEach(function(t) {
  78. var p = document.createElement("p");
  79. if (t.BLACK) {
  80. p.innerHTML = t.WHITE + " - " + t.BLACK + " " + t.SCORE[0] + " : " + t.SCORE[1] + " " +
  81. (t.LIMIT.length != 0 ? "(to " + t.LIMIT + ")" : "(money session)") +
  82. " " + "<a href=" + t.URI + ">WATCH</a>";
  83. } else {
  84. p.innerHTML = t.WHITE + " " +
  85. (t.LIMIT.length != 0 ? "(to " + t.LIMIT + ")" : "(money session)")
  86. + " " + "<a href=/proposal?table=" + t.URI.replace(/\/[^\/]*\//, "") + ">JOIN</a>";
  87. }
  88. table.appendChild(p);
  89. });
  90. }
  91. */
  92. setInterval(fetchTableInfo, 2000);
  93. </script>
  94. </html>