<!DOCTYPE html>
|
<html>
|
<head>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta name="viewport" content="width=device-width, user-scalable=no" />
|
<title>Wyniki brydżowe</title>
|
<link rel="stylesheet" href="bridge.css" type="text/css" />
|
</head>
|
<body>
|
|
<p>
|
<button onclick="addResult()">Dodaj wynik</button>
|
<button onclick="addPlayer()">Dodaj gracza</button>
|
<button onclick="clearAll()">Wyczyść</button>
|
</p>
|
|
<div id="results">
|
</div>
|
|
<div id="overlay">
|
</div>
|
|
<script type="text/javascript" src="bridge_results_table.js"></script>
|
<script type="text/javascript">
|
var resultsTable = new ResultsTable('html', document.getElementById('results'));
|
resultsTable.load();
|
|
function addPlayer() {
|
var result = prompt('Podaj inicjały gracza');
|
if(result) {
|
resultsTable.addPlayer(result);
|
}
|
}
|
|
function addResult() {
|
if(resultsTable.players.length < 4) {
|
alert('Dodaj przynajmniej 4 graczy.');
|
return;
|
}
|
window.open('compute.html');
|
}
|
|
function clearAll() {
|
resultsTable.clear();
|
}
|
|
function saveResult(result, p1, p2, p3, p4) {
|
var lista = document.getElementById('overlay');
|
|
if(p1 == null || p2 == null || p3 == null || p4 == null) {
|
while(lista.lastChild) {
|
lista.removeChild(lista.lastChild);
|
}
|
|
var selectable = [];
|
lista.appendChild(document.createElement('br'));
|
for(var i = 0; i < resultsTable.players.length; i++) {
|
if(p1 == i || p2 == i || p3 == i || p4 == i) {
|
continue;
|
}
|
selectable.push(i);
|
}
|
if(p3 == null && p4 == null && selectable.length == 2) {
|
return saveResult(result, p1, p2, selectable[0], selectable[1]);
|
}
|
|
var p = document.createElement('p');
|
if(p1 == null) {
|
p.appendChild(document.createTextNode('Rozgrywający 1:'));
|
} else if(p2 == null) {
|
p.appendChild(document.createTextNode('Rozgrywający 2:'));
|
} else if(p3 == null) {
|
p.appendChild(document.createTextNode('Przeciwnik 1:'));
|
} else {
|
p.appendChild(document.createTextNode('Przeciwnik 2:'));
|
}
|
lista.appendChild(p);
|
for(var j = 0; j < selectable.length; j++) {
|
var i = selectable[j];
|
var button = document.createElement('button');
|
button.innerText = resultsTable.players[i];
|
button.onclick = (function (j) { return function() {
|
if(p1 == null) {
|
saveResult(result, j, null, null, null);
|
} else if(p2 == null) {
|
saveResult(result, p1, j, null, null);
|
} else if(p3 == null) {
|
saveResult(result, p1, p2, j, null);
|
} else {
|
saveResult(result, p1, p2, p3, j);
|
}
|
} })(i);
|
lista.appendChild(button);
|
}
|
|
button = document.createElement('button');
|
button.innerText = 'Anuluj';
|
button.onclick = function() {
|
lista.style.display = 'none';
|
}
|
|
lista.appendChild(button);
|
lista.style.display = 'block';
|
} else {
|
lista.style.display = 'none';
|
|
var results = [];
|
for(var i = 0; i < resultsTable.players.length; i++) {
|
if(p1 == i || p2 == i) {
|
if(result.dla == 0) {
|
results.push(result.IMP);
|
} else {
|
results.push('-');
|
}
|
} else if(p3 == i || p4 == i) {
|
if(result.dla != 0) {
|
results.push(result.IMP);
|
} else {
|
results.push('-');
|
}
|
} else {
|
results.push('X');
|
}
|
}
|
|
resultsTable.addResult(results);
|
}
|
}
|
|
function handler(event) {
|
var result = event.data;
|
|
setTimeout(function() {
|
saveResult(result, null, null, null, null);
|
}, 1);
|
}
|
|
window.addEventListener('message', handler, false);
|
</script>
|
|
</body>
|
</html>
|