summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-01-20 11:26:45 +0100
committeremkael <emkael@tlen.pl>2019-01-20 11:26:45 +0100
commitcf9f80b5561c25cea7661747f190ff5c67983554 (patch)
tree4196fd4103cf743155ae5ae94d9947f069a58d52 /http
parenta4c619ec6aad97e44d8c6f38e5c510cd7ae66621 (diff)
Fetching data from the API
Diffstat (limited to 'http')
-rw-r--r--http/pkle2018-test.php88
-rw-r--r--http/style.css2
2 files changed, 74 insertions, 16 deletions
diff --git a/http/pkle2018-test.php b/http/pkle2018-test.php
index 238d922..3826d3a 100644
--- a/http/pkle2018-test.php
+++ b/http/pkle2018-test.php
@@ -53,7 +53,64 @@ function typtur(x){
}
}
-function submitit(){
+function loader(show) {
+ document.getElementById("loader").style.display = show ? 'block' : 'none';
+ document.getElementById("sqlbuttons").style.display = show ? 'none' : 'block';
+ document.getElementById("pkltablebox").style.display = show ? 'none' : 'block';
+}
+
+function display() {
+ if (this.status != 200) {
+ alert(this.responseText);
+ } else {
+ var response = JSON.parse(this.responseText);
+ var sqlPary = ['UPDATE `dodatki` SET `pkl` = 0;'];
+ var sqlTeamy = ['UPDATE `addons` SET `mastr` = 0;'];
+ var pklHTML = ['<tr><td class="t">Miejsce</td><td class="t">&nbsp;&nbsp;&nbsp;PKL&nbsp;&nbsp;&nbsp;</td></tr>'];
+ for (var place = 1; place <= parseInt(document.getElementsByName('iuc')[0].value); place++) {
+ sqlPary.push('UPDATE `dodatki` SET `pkl` = ' + response[place] + ' WHERE `miejsce` = ' + place + ';');
+ sqlTeamy.push('UPDATE `addons` SET `mastr` = ' + response[place] + ' WHERE `place` = ' + place + ';');
+ pklHTML.push('<tr><td class="t">' + place + '</td><td class="t">' + response[place] + '</td></tr>');
+ }
+ pklHTML.push('<tr><td class="p">SUMA PKL</td><td class="t">' + response['sum'] + '</td></tr>');
+ document.getElementById('outsql').innerHTML = sqlPary.join("\n");
+ document.getElementById('outsql2').innerHTML = sqlTeamy.join("\n");
+ document.getElementById("pkltable").innerHTML = pklHTML.join("");
+ }
+ loader(false);
+}
+
+function sendit(form) {
+ var params = {
+ type: parseInt(form.typ.value),
+ contestants: parseInt(form.iuc.value),
+ title_sum: parseFloat(form.swk.value),
+ tournament_rank: 8-form.rng.value,
+ over39_boards: parseInt(form.rozdan.value)
+ }
+ var tourtypes = ['tk', 'to', 'tp', 'ok', 'ok1', 'ot', 'gp', 'gg'];
+ params['manual[players_coefficient]'] = parseFloat(form.zaw.value);
+ params['manual[min_points]'] = parseInt(form['min' + (8-params.tournament_rank) + (params.over39_boards ? '_' : '')].value);
+ params['manual[tournament_weight]'] = parseInt(form['r' + tourtypes[params.tournament_rank] + (params.over39_boards ? '_' : '')].value);
+ for (var i = 0; i < 2; i++) {
+ params['manual[points_cutoffs]['+i+'][0]'] = parseFloat(form['pru'+(i+1)].value) / 100;
+ params['manual[points_cutoffs]['+i+'][1]'] = parseFloat(form['prp'+(i+1)].value) / 100;
+ }
+ params['manual[points_cutoffs][2][0]'] = parseFloat(form.pru3.value) / 100;
+ params['manual[points_cutoffs][2][1]'] = 0;
+ var paramString = [];
+ for (var param in params) {
+ paramString.push(param + '=' + params[param]);
+ }
+ loader(true);
+ var xhr = new XMLHttpRequest();
+ xhr.addEventListener('load', display);
+ xhr.open('POST', 'api.php', true);
+ xhr.setRequestHeader("Content-Type", 'application/x-www-form-urlencoded');
+ xhr.send(paramString.join('&'));
+}
+
+function submitit(ev){
if( document.getElementsByName("typ")[0].checked ||
document.getElementsByName("typ")[1].checked ||
document.getElementsByName("typ")[2].checked ){
@@ -73,9 +130,7 @@ function submitit(){
if( t.value!=null && t.value!='' && isFinite(t.value) ){
t = document.getElementById("swk");
if( t.value!=null && t.value!='' && isFinite(t.value) ){
-
- document.getElementById("pkl").submit();
-
+ sendit(ev);
} else {
alert('Brak sumy WK!');
t.select();
@@ -101,7 +156,7 @@ function submitit(){
</script>
</head>
<body style="background-color: #F0F0F0; background-image: none">
- <form id="pkl" method="post" action="pkle2018.php">
+ <form id="pkl">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/logo_pzbs.gif"></td>
@@ -209,23 +264,24 @@ function submitit(){
<tr><td colspan="5">&nbsp;</td></tr>
<tr>
<td align="CENTER" colspan="2">
- <input type="button" value="Policz PKLe" onclick="submitit()"></td>
+ <input type="button" value="Policz PKLe" onclick="submitit(this.form)"></td>
<td colspan="3">
- <input type="button" value="SQL dla JFR Pary" onclick="document.getElementById('outsql').style.display=(document.getElementById('outsql').style.display=='none') ? 'block' : 'none';"><input type="button" value="SQL dla JFR Teamy" onclick="document.getElementById('outsql2').style.display=(document.getElementById('outsql2').style.display=='none') ? 'block' : 'none';">
+ <div id="sqlbuttons">
+ <input type="button" value="SQL dla JFR Pary" onclick="document.getElementById('outsql').style.display=(document.getElementById('outsql').style.display=='none') ? 'block' : 'none';document.getElementById('outsql2').style.display='none'"><input type="button" value="SQL dla JFR Teamy" onclick="document.getElementById('outsql2').style.display=(document.getElementById('outsql2').style.display=='none') ? 'block' : 'none';document.getElementById('outsql').style.display='none'">
+ </div>
</td>
</tr>
<tr><td colspan="2" align="center">
- <table><tr><td class="t">Miejsce</td><td class="t">&nbsp;&nbsp;&nbsp;PKL&nbsp;&nbsp;&nbsp;</td></tr>
- <tr><td class="p">SUMA PKL</td><td class="t"></td></tr>
- </table>
- </td><td colspan="3" valign="top"><span id="outsql" style="display: none">
- UPDATE `dodatki` SET `pkl`=0;<br />
- </span></td>
- <td colspan="3" valign="top"><span id="outsql2" style="display: none">
- UPDATE `addons` SET `mastr`=0;<br />
- </span></td></tr>
+ <div id="pkltablebox">
+ <table id="pkltable"><tr><td class="t">Miejsce</td><td class="t">&nbsp;&nbsp;&nbsp;PKL&nbsp;&nbsp;&nbsp;</td></tr>
+ <tr><td class="p">SUMA PKL</td><td class="t"></td></tr>
+ </table>
+ </div>
+ </td><td colspan="3" valign="top"><pre id="outsql" style="display: none"></pre></td>
+ <td colspan="3" valign="top"><pre id="outsql2" style="display: none"></pre></td></tr>
<tr><td colspan="5" class="copyright">&copy;'2009, Jan Romański dla PZBS</td></tr>
</table>
</form>
+ <div id="loader">Cierpliwości, liczę...</div>
</body>
</html>
diff --git a/http/style.css b/http/style.css
index f226e5b..44394de 100644
--- a/http/style.css
+++ b/http/style.css
@@ -9,5 +9,7 @@ td.t {padding: 1px; border: 1px solid #008000; text-align: center; font-size: 10
td.s {padding: 1px; border: 1px solid #A0A0A0; text-align: center; font-size: 10pt; white-space: nowrap; color: #A0A0A0}
td.p {padding: 1px; font-size: 10pt}
hr {color: #0000A0}
+#loader {font-family: Arial;width: 100%; height: 100%; position: fixed; top: 0; left: 0; background: rgba(255, 255, 255, 0.7); display: none; text-align: center; font-size: 64px;}
+#pkltablebox, #sqlbuttons {display:none}
/* Copyright */
.copyright {padding: 0px; color: #555555; font-size: 8pt; font-family: Arial; text-align: center; border: 1px dotted #004000}