commit | author | age
|
7f8ceb
|
1 |
<!DOCTYPE html> |
JK |
2 |
<html> |
|
3 |
<head> |
|
4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
5 |
<meta name="viewport" content="width=device-width, user-scalable=no" /> |
|
6 |
<title>Wyniki brydżowe</title> |
|
7 |
<link rel="stylesheet" href="bridge.css" type="text/css" /> |
|
8 |
</head> |
|
9 |
<body> |
|
10 |
|
|
11 |
<p> |
|
12 |
<button onclick="addResult()">Dodaj wynik</button> |
|
13 |
<button onclick="addPlayer()">Dodaj gracza</button> |
|
14 |
<button onclick="clearAll()">Wyczyść</button> |
|
15 |
</p> |
|
16 |
|
|
17 |
<div id="results"> |
|
18 |
</div> |
|
19 |
|
|
20 |
<div id="overlay"> |
|
21 |
</div> |
|
22 |
|
450db0
|
23 |
<script type="text/javascript" src="bridge_results_table.js"></script> |
7f8ceb
|
24 |
<script type="text/javascript"> |
JK |
25 |
var resultsTable = new ResultsTable('html', document.getElementById('results')); |
|
26 |
resultsTable.load(); |
|
27 |
|
|
28 |
function addPlayer() { |
|
29 |
var result = prompt('Podaj inicjały gracza'); |
|
30 |
if(result) { |
|
31 |
resultsTable.addPlayer(result); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
function addResult() { |
|
36 |
if(resultsTable.players.length < 4) { |
|
37 |
alert('Dodaj przynajmniej 4 graczy.'); |
|
38 |
return; |
|
39 |
} |
|
40 |
window.open('compute.html'); |
|
41 |
} |
|
42 |
|
|
43 |
function clearAll() { |
|
44 |
resultsTable.clear(); |
|
45 |
} |
|
46 |
|
|
47 |
function saveResult(result, p1, p2, p3, p4) { |
|
48 |
var lista = document.getElementById('overlay'); |
|
49 |
|
|
50 |
if(p1 == null || p2 == null || p3 == null || p4 == null) { |
|
51 |
while(lista.lastChild) { |
|
52 |
lista.removeChild(lista.lastChild); |
|
53 |
} |
|
54 |
|
|
55 |
var selectable = []; |
|
56 |
lista.appendChild(document.createElement('br')); |
|
57 |
for(var i = 0; i < resultsTable.players.length; i++) { |
|
58 |
if(p1 == i || p2 == i || p3 == i || p4 == i) { |
|
59 |
continue; |
|
60 |
} |
|
61 |
selectable.push(i); |
|
62 |
} |
|
63 |
if(p3 == null && p4 == null && selectable.length == 2) { |
|
64 |
return saveResult(result, p1, p2, selectable[0], selectable[1]); |
|
65 |
} |
|
66 |
|
|
67 |
var p = document.createElement('p'); |
|
68 |
if(p1 == null) { |
|
69 |
p.appendChild(document.createTextNode('Rozgrywający 1:')); |
|
70 |
} else if(p2 == null) { |
|
71 |
p.appendChild(document.createTextNode('Rozgrywający 2:')); |
|
72 |
} else if(p3 == null) { |
|
73 |
p.appendChild(document.createTextNode('Przeciwnik 1:')); |
|
74 |
} else { |
|
75 |
p.appendChild(document.createTextNode('Przeciwnik 2:')); |
|
76 |
} |
|
77 |
lista.appendChild(p); |
|
78 |
for(var j = 0; j < selectable.length; j++) { |
|
79 |
var i = selectable[j]; |
|
80 |
var button = document.createElement('button'); |
|
81 |
button.innerText = resultsTable.players[i]; |
|
82 |
button.onclick = (function (j) { return function() { |
|
83 |
if(p1 == null) { |
|
84 |
saveResult(result, j, null, null, null); |
|
85 |
} else if(p2 == null) { |
|
86 |
saveResult(result, p1, j, null, null); |
|
87 |
} else if(p3 == null) { |
|
88 |
saveResult(result, p1, p2, j, null); |
|
89 |
} else { |
|
90 |
saveResult(result, p1, p2, p3, j); |
|
91 |
} |
|
92 |
} })(i); |
|
93 |
lista.appendChild(button); |
|
94 |
} |
|
95 |
|
|
96 |
button = document.createElement('button'); |
|
97 |
button.innerText = 'Anuluj'; |
|
98 |
button.onclick = function() { |
|
99 |
lista.style.display = 'none'; |
|
100 |
} |
|
101 |
|
|
102 |
lista.appendChild(button); |
|
103 |
lista.style.display = 'block'; |
|
104 |
} else { |
|
105 |
lista.style.display = 'none'; |
|
106 |
|
|
107 |
var results = []; |
|
108 |
for(var i = 0; i < resultsTable.players.length; i++) { |
|
109 |
if(p1 == i || p2 == i) { |
|
110 |
if(result.dla == 0) { |
|
111 |
results.push(result.IMP); |
|
112 |
} else { |
|
113 |
results.push('-'); |
|
114 |
} |
|
115 |
} else if(p3 == i || p4 == i) { |
|
116 |
if(result.dla != 0) { |
|
117 |
results.push(result.IMP); |
|
118 |
} else { |
|
119 |
results.push('-'); |
|
120 |
} |
|
121 |
} else { |
|
122 |
results.push('X'); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
resultsTable.addResult(results); |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
function handler(event) { |
|
131 |
var result = event.data; |
|
132 |
|
|
133 |
setTimeout(function() { |
|
134 |
saveResult(result, null, null, null, null); |
|
135 |
}, 1); |
|
136 |
} |
|
137 |
|
|
138 |
window.addEventListener('message', handler, false); |
|
139 |
</script> |
|
140 |
|
|
141 |
</body> |
|
142 |
</html> |