This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
152 lines (110 loc) · 3.58 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Swaeg QR-code solutions</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css" media="screen">
.sold {
color: #adadad;
text-decoration: line-through;
}
.hilight {
font-size: 24px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div id="reader" style="width:100%; height: 450px;"></div>
</div>
<div class="col-sm-6 col-sm-offset-2">
<div class="well">
<div id="info">
Some info here....
</div>
<ul id="tix"></ul>
</div>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='/lib/jquery-1.11.3.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script src="lib/jsqrcode-combined.min.js"></script>
<script src="lib/html5-qrcode.js"></script>
<script>
$(document).ready(function() {
var allTickets, soldTickets;
$.getJSON('test.json', function(data) {
localStorage.setItem('allTickets', JSON.stringify(data));
soldTickets = localStorage['soldTickets'];
allTickets = data;
$.each(data, function(i, d) {
$('#tix').append('<li data-ticketcode="' + d.ticketcode.toUpperCase() + '">' + d.etunimi +' ' + d.sukunimi + ' / ' + d.ticketcode.toUpperCase() + ' </li>');
});
if (soldTickets != null) {
soldTickets = JSON.parse(soldTickets);
$.each(soldTickets, function(i, d) {
markAsSold(d, 'sold');
});
}
});
function addSoldTicket(data) {
markAsSold({ticketcode: data}, 'hilight');
var tickets = JSON.parse(localStorage['allTickets']);
var info = $.grep(tickets, function(d) {
if (d.ticketcode.toUpperCase() == data) {
return d;
}
});
alert('OK!\n\nNimi: ' + info[0]['etunimi'] + ' ' + info[0]['sukunimi'] + '\nLipputyyppi: ' + info[0]['lipputyyppi'] + '\nKoodi: ' + data );
var sold = localStorage.getItem('soldTickets');
if (sold == null) {
sold = [{
ticketcode: data
}];
} else {
sold = JSON.parse(localStorage['soldTickets']);
sold.push({ticketcode: data});
}
localStorage['soldTickets'] = JSON.stringify(sold);
markAsSold({ticketcode: data}, 'sold');
// note the url - needs to be localhost or whereever the jsonp-server is
$.getJSON('http://localhost:8080/save?callback=?', {'ticket': data}, function(resdata) {
console.log(resdata.msg);
});
}
function markAsSold(data, className) {
$('#tix').find('[data-ticketcode="' + data.ticketcode + '"]').attr('class', className);
}
$('#reader').html5_qrcode(
function(data) {
var isSold = false;
$('#info').html('Saatiin koodi: ' + data);
soldTickets = localStorage.getItem('soldTickets');
if (soldTickets != null) {
soldTickets = JSON.parse(localStorage.getItem('soldTickets'));
$.each(soldTickets, function(i, d) {
if (d.ticketcode.toUpperCase() == data) {
alert('Lippu on lunastettu jo – Vedä pataan?');
isSold = true;
}
});
}
if (isSold == false) {
addSoldTicket(data);
}
},
function(error) {},
function(videoError) {}
);
});
</script>
</body>
</html>