-
Notifications
You must be signed in to change notification settings - Fork 0
/
partido.html
347 lines (300 loc) · 12.3 KB
/
partido.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<title>Partido</title>
<!-- Bootstrap core CSS -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="../css/cover.css" rel="stylesheet">
<link href="../css/jumbotron-narrow.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="site-wrapper">
<div class="site-wrapper-inner">
<ul class="nav nav-pills pull-left">
<li><a id="jugadorButton" href="/jugador"></a></li>
</ul>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1 id="nombrePartido"></h1>
<p id="infoPartido"></p>
<p>
<button id="botonVoy" class="btn btn-primary" style="display:none">
Voy
</button>
<button id="botonSuplente" class="btn btn-primary" style="display:none">
Suplente
</button>
<button id="botonMeBajo" class="btn btn-primary" style="display:none">
Me bajo
</button>
</p>
<div id="alertContainer"></div>
</div>
</div>
<div class="col-md-4 panel panel-default panelTitulares">
<div class="panel-heading">
<h3 class="panel-title">Titulares</h3>
</div>
<div class="panel-body">
<ul id="jugadoresContainer" class="list-group">
</ul>
</div>
</div>
<div class="col-md-4 panel panel-default panelSuplentes">
<div class="panel-heading">
<h3 class="panel-title">Suplentes</h3>
</div>
<div id="suplentesContainer" class="panel-body">
</div>
</div>
<div class="col-md-4 panel panel-default panelNoVoy">
<div class="panel-heading">
<h3 class="panel-title">No van</h3>
</div>
<div id="nojueganContainer" class="panel-body">
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<script src="../js/docs.min.js"></script>
<script>
var AlertUtils = {
showSuccessAlert : function(title, message) {
$("#alertContainer").empty();
var node = $("<div id='successAlert' class='alert alert-success alert-dismissable'>"+
"<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>"+
"<strong>"+title+": </strong>"+message+"</div>");
$("#alertContainer").append(node);
},
showErrorAlert : function(title, message) {
$("#alertContainer").empty();
var node = $("<div id='errorAlert' class='alert alert-danger alert-dismissable'>"+
"<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>"+
"<strong>"+title+": </strong>"+message+"</div>");
$("#alertContainer").append(node);
}
};
var Loading = {
show : function() {
if ($("#loading").length > 0) {
return;
}
var node = $('<div id="loading" style="height:100%; width:100%; position:absolute; top: 0px; left: 0px;'+
'background-color: rgba(100,100,100,0.5);"> '+
'<div style="text-align: center; margin-top: 25%;"><span><img src="images/loading.gif"></span> Loading...</div>'+
'</div>');
$("body").append(node);
},
hide : function() {
$("#loading").remove();
}
};
var params = [], hash;
var q = document.URL.split('?')[1];
if(q != undefined){
q = q.split('&');
for(var i = 0; i < q.length; i++){
hash = q[i].split('=');
params.push(hash[1]);
params[hash[0]] = hash[1];
}
}
var currentUser;
$.ajax({
url : "/api/jugadores/"+params['user'],
type: "GET",
dataType: "json",
data : {},
success: function(data, textStatus, jqXHR) {
currentUser = data;
$('#jugadorButton').text(currentUser.name);
$('#jugadorButton').attr('href','/jugador?code='+params['user']);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Jugador no encontrado: "+textStatus);
AlertUtils.showErrorAlert("Error","Jugador no encontrado");
}
});
$('#botonVoy').click(function() {
Loading.show();
$.ajax({
url : "/api/partidos/"+params['code']+"/jugadores",
type: "POST",
dataType: "json",
data : {user: params['user'],
as : "titular"
},
success: function(data, textStatus, jqXHR) {
var found = false;
for (var index in data.jugadores) {
var jugador = data.jugadores[index];
if (jugador.email === currentUser.email) {
found = true;
break;
}
}
if (found) {
AlertUtils.showSuccessAlert("Perfecto!","Sos parte de los titulares.");
}
else {
AlertUtils.showSuccessAlert("No hay vacantes!","Quedaste anotado como suplente.");
}
refresh();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Usuario no agregado");
AlertUtils.showErrorAlert("Error","Jugador no agregado al partido!");
}
});
});
$('#botonSuplente').click(function() {
Loading.show();
$.ajax({
url : "/api/partidos/"+params['code']+"/jugadores",
type: "POST",
dataType: "json",
data : {user: params['user'],
as : "suplente"
},
success: function(data, textStatus, jqXHR) {
console.log("Usuario agregado");
AlertUtils.showSuccessAlert("Perfecto!","Sos parte de los suplentes.");
refresh();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Usuario no agregado");
AlertUtils.showErrorAlert("Error","Jugador no agregado al partido!");
}
});
});
$('#botonMeBajo').click(function() {
Loading.show();
$.ajax({
url : "/api/partidos/"+params['code']+"/jugadores",
type: "POST",
dataType: "json",
data : {user: params['user'],
as : "nojuega"
},
success: function(data, textStatus, jqXHR) {
console.log("Usuario agregado");
AlertUtils.showSuccessAlert("Que lastima!","Te esperamos el proximo partido.");
refresh();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Usuario no agregado");
AlertUtils.showErrorAlert("Error","Jugador no agregado al partido!");
}
});
});
var refresh = function() {
Loading.show();
$.ajax({
url : "/api/partidos/"+params['code'],
type: "GET",
dataType: "json",
data : {},
success: function(data, textStatus, jqXHR) {
console.log(data);
$('#nombrePartido').text(data.nombre);
var infoPartido = "El partido es en la cancha "+data.cancha+", el dia "+data.fecha+" a las "+data.hora+" hs. Precio: "+data.precio+".";
$('#infoPartido').text(infoPartido);
$("#jugadoresContainer").empty();
var count = 0;
for (var i in data.jugadores) {
var jugador = data.jugadores[i];
//var row = $("<div class='row'><p>"+jugador.name+": "+jugador.email+"</p></div>");
var row = $("<li class='list-group-item'><span class='badge'>"+jugador.estrellas+"</span>"+
jugador.name+"</li>");
$("#jugadoresContainer").append(row);
count++;
}
$("#suplentesContainer").empty();
for (var i in data.suplentes) {
var jugador = data.suplentes[i];
var row = $("<li class='list-group-item'><span class='badge'>"+jugador.estrellas+"</span>"+
jugador.name+"</li>");
$("#suplentesContainer").append(row);
}
$("#nojueganContainer").empty();
for (var i in data.nojuegan) {
var jugador = data.nojuegan[i];
var row = $("<li class='list-group-item'><span class='badge'>"+jugador.estrellas+"</span>"+
jugador.name+"</li>");
$("#nojueganContainer").append(row);
}
while (count < data.cantidadJugadores) {
var row = $("<li class='list-group-item'>?</li>");
$("#jugadoresContainer").append(row);
count++;
}
refreshButtons();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Partido no encontrado: "+textStatus);
AlertUtils.showErrorAlert("Error","Partido no encontrado!");
}
});
};
var refreshButtons = function(){
Loading.show();
$.ajax({
url : "/api/partidos/"+params['code']+"/voy?user="+params['user'],
type: "GET",
dataType: "json",
data : {},
success: function(data, textStatus, jqXHR) {
if (data.as) {
if (data.as == "titular") {
$("#botonVoy").hide();
$("#botonSuplente").show();
$("#botonMeBajo").show();
}
if (data.as == "suplente"){
$("#botonVoy").show();
$("#botonSuplente").hide();
$("#botonMeBajo").show();
}
if (data.as == "nojuega"){
$("#botonVoy").show();
$("#botonSuplente").show();
$("#botonMeBajo").hide();
}
}
else {
$("#botonVoy").show();
$("#botonSuplente").show();
$("#botonMeBajo").show();
}
Loading.hide();
},
error: function (jqXHR, textStatus, errorThrown) {
AlertUtils.showErrorAlert("Error","Usuario no encontrado!");
Loading.hide();
}
});
};
refresh();
</script>
</body>
</html>