-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
546 lines (500 loc) · 19.4 KB
/
index.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<!DOCTYPE html>
<html>
<head>
<title>COCARU - Controle de Cartões RU</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[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.3.0/respond.min.js"></script>
<![endif]-->
<link rel="shortcut icon" href="favicon/favicon.ico">
<link rel="icon" sizes="16x16 32x32 64x64" href="favicon/favicon.ico">
<link rel="icon" type="image/png" sizes="196x196" href="favicon/favicon-192.png">
<link rel="icon" type="image/png" sizes="160x160" href="favicon/favicon-160.png">
<link rel="icon" type="image/png" sizes="96x96" href="favicon/favicon-96.png">
<link rel="icon" type="image/png" sizes="64x64" href="favicon/favicon-64.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16.png">
<link rel="apple-touch-icon" href="favicon/favicon-57.png">
<link rel="apple-touch-icon" sizes="114x114" href="favicon/favicon-114.png">
<link rel="apple-touch-icon" sizes="72x72" href="favicon/favicon-72.png">
<link rel="apple-touch-icon" sizes="144x144" href="favicon/favicon-144.png">
<link rel="apple-touch-icon" sizes="60x60" href="favicon/favicon-60.png">
<link rel="apple-touch-icon" sizes="120x120" href="favicon/favicon-120.png">
<link rel="apple-touch-icon" sizes="76x76" href="favicon/favicon-76.png">
<link rel="apple-touch-icon" sizes="152x152" href="favicon/favicon-152.png">
<link rel="apple-touch-icon" sizes="180x180" href="favicon/favicon-180.png">
<meta name="msapplication-TileColor" content="#FFFFFF">
<meta name="msapplication-TileImage" content="favicon/favicon-144.png">
<meta name="msapplication-config" content="favicon/browserconfig.xml">
<style>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #E0E0E0;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input {
margin-bottom: 10px;
}
.tab-content.form-signin{
background-color: #fff;
border: 1px solid #ddd;
border-top:0;
}
.container.logo {
text-align: center;
margin-bottom: 10px;
}
.tab-content form-signin {
background-color: #FFF;
border: 1px solid #DDD;
border-top: none;
}
fieldset.form-group {
margin-top:10px;
margin-bottom:0px;
}
.no-padding {
padding: 0;
}
form small {
display: block;
margin-bottom: 10px;
}
.container .alert-row:first-of-type [class*="col-"]{
padding-bottom:0px;
}
.container .alert-row {
display: none;
}
#login-container, #info-container {
display: none;
}
.container [class*="col-"] {
padding: 1.5em;
background-color: #fff;
}
.alert:last-of-type {
margin-bottom: 0px;
}
.alert {
display: none;
}
/* nav fix */
.nav-tabs>li {
height:62px;
}
.nav-tabs>li>a, .nav-tabs>li>a>div {
height: 85px;
display:table;
}
.nav-tabs>li>a span {
display:table-cell;
vertical-align:middle;
}
li[role="presentation"] a {
width: 100%;
}
table {
width: 100%;
text-align: center;
}
.card {
padding: 1.5em;
padding-bottom: 1em;
background-color: #fff;
border-radius: 10px;
color: #424242;
white-space: nowrap;
box-shadow: 0px 4px 8px 0px rgba(0,0,0,0.15);
cursor: pointer;
}
.card-wrapper:not(:last-child):not(:first-child) {
padding-left: 6.66px;
padding-right: 6.66px;
display: table-cell;
}
.card-wrapper:first-child {
padding-right: 13.33px;
display: table-cell;
}
.card-wrapper:last-child {
padding-left: 13.33px;
display: table-cell;
}
.row {
margin: 0px;
}
.card p {
display: inline-block;
margin-left: 5px;
margin-right: 5px;
}
.returnable, .returnable .stripe {
color: #BF360C;
border-color: #BF360C;
}
.returnable .stripe::before {
content: 'Retornar';
}
.available, .available .stripe {
color: #1B5E20;
border-color: #1B5E20;
}
.available .stripe::before {
content: 'Disponível';
}
.available .glyphicon-user + p::before {
content: '______';
}
.stripe::before {
color: rgba(255, 255, 255, 0.8);
content: 'Indisponível';
}
div.logout {
text-align: center;
}
.stripe {
margin-left: -1.5em;
margin-right: -1.5em;
height:20px;
border-bottom: 20px solid #424242;
text-align: center;
color: #fff;
}
h1 {
margin-bottom: 20px;
}
#cards-container {
width: 100%;
display: table;
table-layout: fixed;
margin-bottom: 20px;
}
#logs-container {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0px 4px 8px 0px rgba(0,0,0,0.15);
}
table th {
text-align: center;
}
table.dataTable thead th {
border-bottom: 1px solid #dddddd;
}
table.dataTable tfoot th {
border-top: 1px solid #dddddd;
}
table.dataTable.row-border tbody th, table.dataTable.row-border tbody td, table.dataTable.display tbody th, table.dataTable.display tbody td {
border-top: 1px solid #dddddd;
}
table.dataTable.cell-border tbody th, table.dataTable.cell-border tbody td {
border-top: 1px solid #dddddd;
border-right: 1px solid #dddddd;
}
table.dataTable.cell-border tbody tr td:first-child {
border-left: 1px solid #dddddd;
}
table.dataTable.no-footer {
border-bottom: 1px solid #dddddd;
}
.dataTables_wrapper.no-footer .dataTables_scrollBody {
border-bottom: 1px solid #dddddd;
}
.dataTables_wrapper .row {
display: flex;
}
@media only screen and (max-width : 480px) {
table {
font-size: 0.75em;
}
}
.hello h1 {
float: left;
}
.hello button {
float: right;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container logo">
<img src="favicon/favicon-72.png"/>
<h3>Controle de Cartões RU</h3>
</div>
<div class="container" id="login-container">
<div class="row">
<!-- Nav tabs -->
<ul class="nav nav-tabs form-signin no-padding nav-justified" role="tablist" style="padding-bottom:0px;">
<li role="presentation" class="active"><a href="#signin" aria-controls="home" role="tab" data-toggle="tab"><h4>Entrar</h4></a></li>
<li role="presentation"><a href="#register" aria-controls="register" role="tab" data-toggle="tab"><h4>Registrar</h4></a></li>
<li role="presentation"><a href="#reset" aria-controls="reset" role="tab" data-toggle="tab"><h4>Recuperar senha</h4></a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content form-signin">
<div role="tabpanel" class="tab-pane active" id="signin">
<form id="signInForm" class="form-signin" name="signin">
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" id="inputEmailSignIn" name="inputEmailSignIn" class="form-control" placeholder="Email" required autofocus>
<label for="inputPassword" class="sr-only">Senha</label>
<input type="password" id="inputPasswordSignIn" name="inputPasswordSignIn" class="form-control" placeholder="Senha" required>
<button id="signinBtn" class="btn btn-lg btn-primary btn-block" type="submit">Entrar</button>
</form>
</div>
<div role="tabpanel" class="tab-pane" id="register">
<form id="registerForm" class="form-signin" name="register">
<label for="inputName" class="sr-only">Nome</label>
<input type="text" id="inputNameRegister" name="inputNameRegister" class="form-control" placeholder="Nome" required autofocus="">
<label for="inputName" class="sr-only">Nome</label>
<input type="email" id="inputEmailRegister" name="inputEmailRegister" class="form-control" placeholder="Email" required autofocus="">
<label for="inputPassword" class="sr-only">Senha</label>
<input type="password" id="inputPasswordRegister" name="inputPasswordRegister" class="form-control" placeholder="Senha" required>
<label for="confirmPassword" class="sr-only">Confirmar senha</label>
<input type="password" id="confirmPassword" class="form-control" placeholder="Confirmar senha" required>
<small id="passwordHelp" class="form-text text-muted">No mínimo 6 caracteres</small>
<button id="registerBtn" class="btn btn-lg btn-primary btn-block" type="submit">Registrar</button>
</form>
</div>
<div role="tabpanel" class="tab-pane" id="reset">
<form id="resetForm" class="form-signin" name="reset">
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" id="inputEmailReset" name="inputEmailReset" class="form-control" placeholder="Email" required autofocus>
<button id="resetBtn" class="btn btn-lg btn-primary btn-block" type="submit">Solicitar mudança</button>
</form>
</div>
</div>
</div>
</div>
<!-- -->
<!-- info-container -->
<!-- <div class="col-md-10 col-md-offset-1 col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-1 col-lg-8 col-lg-offset-2"> -->
<div class="container" id="info-container">
<div class="row hello">
<h1 id="hello"></h1>
<button id="logout" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> Sair</button>
</div>
<!-- cards row -->
<div id="cards-container">
</div>
<!-- end cards row -->
<!-- log div -->
<div id="logs-container">
<table id="myTable" class="table diplay cell-border" cellspacing="0" width="100%">
</table>
</div>
<!-- end log div -->
</div>
<script src="https://www.gstatic.com/firebasejs/4.3.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyCXAx7F_pWgNkfBqMIr3wzrUDEVZVBORkM",
authDomain: "caru-47212.firebaseapp.com",
databaseURL: "https://caru-47212.firebaseio.com",
projectId: "caru-47212",
storageBucket: "caru-47212.appspot.com",
messagingSenderId: "293652356463"
};
firebase.initializeApp(config);
</script>
<script src="moment.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script>
var users = {};
var cards = {};
$(document).ready(function() {
var newUser = false;
var dataTable = $('#myTable').DataTable({
pageLength: 5,
columns:
[
{ title: "Usuário" },
{ title: "Tipo" },
{ title: "Cartão" },
{
title: "Data/Hora",
render: function(data, type, row){
if (type == "sort" || type == 'type')
return data;
return moment(new Date(data)).format("HH:mm, DD/MM/YYYY");
}
}
],
order: [[ 3, "desc" ]],
language: {
"sProcessing": "A processar...",
"sLengthMenu": "Mostrar _MENU_ registos",
"sZeroRecords": "Não foram encontrados resultados",
"sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registos",
"sInfoEmpty": "Mostrando de 0 até 0 de 0 registos",
"sInfoFiltered": "(filtrado de _MAX_ registos no total)",
"sInfoPostFix": "",
"sSearch": "Procurar:",
"sUrl": "",
"oPaginate": {
"sFirst": "Primeiro",
"sPrevious": "Anterior",
"sNext": "Seguinte",
"sLast": "Último"
}
}
});
$('#registerForm').submit(function(e){
e.preventDefault();
var email = $('#inputEmailRegister').val();
var password = $('#inputPasswordRegister').val();
firebase.auth().createUserWithEmailAndPassword(email, password).then(function(){
newUser = true;
}).catch(function(error) {
alert(error.message);
console.log(error.message);
});
});
$('#signInForm').submit(function(e){
e.preventDefault();
var email = $('#inputEmailSignIn').val();
var password = $('#inputPasswordSignIn').val();
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
console.log(error.message);
alert(error.message);
});
});
$('#resetForm').click(function(e){
e.preventDefault();
var email = $('#inputEmailReset').val();
firebase.auth().sendPasswordResetEmail(email).then(function() {
alert("Password reset email sent.");
}, function(error) {
alert(error);
});
});
$('#logout').click(function(){
if (confirm("Você está prestes a sair do sistema."))
firebase.auth().signOut();
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
firebase.database().ref('users').on('value', function(snapshot) {
if(snapshot.val() !== null){
users = snapshot.val();
console.log(user.uid);
$('#hello').text('Olá, '+ users[user.uid].name +'!');
}
});
firebase.database().ref('cards').on('value', function(snapshot) {
if(snapshot.val() !== null)
drawCards(snapshot.val(), user);
});
firebase.database().ref('log').orderByChild("timestamp").limitToLast(20).on('child_added', function(snapshot) {
if(snapshot.val() !== null)
drawLog(snapshot.val());
});
if(newUser){
setUserName($('#inputNameRegister').val(), user);
newUser = false;
}
signIn();
} else {
signOut();
}
});
function drawCards(cards, user) {
$('#cards-container').html('');
$.each(cards, function(index, card) {
$('#cards-container').append(
'<div class="card-wrapper">'+
'<div id="' + index + '" class="card'+ (card.userid == 0 ? ' available' : (card.userid == user.uid ? ' returnable' : '')) + '">'+
'<div class="card-id">'+
'<span class="glyphicon glyphicon-barcode" aria-hidden="true"></span>'+
'<p>'+index+'</p>'+
'</div>'+
'<div class="holder">'+
'<span class="glyphicon glyphicon-user" aria-hidden="true"></span>'+
'<p>'+ (card.userid == 0 ? '' : users[card.userid].name) +'</p>'+
'</div>'+
'<div class="stripe"></div>'+
'</div>'+
'</div>'
);
});
$('.card').on('click', function(){
var available = $(this).hasClass("available");
var returnable = $(this).hasClass("returnable");
if (available || returnable){
var update = {}
update['cards/' + this.id] = {"userid": (available ? user.uid : 0)}
firebase.database().ref().update(update);
}
});
}
function drawLog(log) {
dataTable.row.add([
users[log.triggerer].name,
(log.userid == 0 ? 'Devolução' : 'Retirada'),
log.cardid,
log.timestamp
]).draw();
}
function setUserName(name, user) {
if (user != null) {
firebase.database().ref('users/' + user.uid + '/name').set($('#inputNameRegister').val())
.then(function() {
console.log('updated name');
})
.catch(function(error) {
console.log(error);
});
}
}
function signIn(){
$('#login-container').hide();
$('#info-container').show();
}
function signOut(){
$('#info-container').hide();
$('#login-container').show();
$('#login-container form').trigger('reset');
}
function updateProfileFields(user){
firebase.database().ref('users/' + user.uid).on('value', function(snapshot) {
if(snapshot.val() !== null)
console.log(snapshot.val());
});
}
});
</script>
</body>
</html>