-
Notifications
You must be signed in to change notification settings - Fork 1
/
track.html
377 lines (344 loc) · 13.7 KB
/
track.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>ScanItOn | View Your Packages</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.css" rel = "stylesheet">
<link href="css/dashboard-css.css" rel = "stylesheet">
<link href='http://fonts.googleapis.com/css?family=Lato:300,400,900' rel='stylesheet' type='text/css'>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"><b>ScanItOn</b></a>
</div>
<div class="collapse navbar-collapse ">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="" id="login" style="display:inline-block"></a>
<input id="logout" class="btn btn-success" type="submit" value="Logout" style="display:inline-block" />
</li>
</ul>
<ul class="nav navbar-nav navbar-left">
<li><a href="create.html">Create</a></li>
<li><a href="#" class="active">Track</a></li>
</ul>
</div>
</div>
</nav>
<!-- /End of Navbar -->
<!-- Start TO DO & Step 1-2-3 Sections -->
<div class="generateqr-container" style="">
<div class="col-md-3 col-sm-3">
<div class="create-envelopes">
<ul class="nav nav-list">
<li class="nav-header">
Tasks
</li>
<li>
<a href="create.html">Create New</a>
</li>
<li class="active">
<a href="#">Track Packages</a>
</li>
</ul>
</div>
</div>
<div class="col-md-9 col-sm-9" style="">
<div class="create-envelopes" style="height: 100%">
<div class="container">
<h1 class="dashboard-title">Your Packages</h1>
<div id="tableControls" style="display:none">
<a href="#" id="loadNext" class="pull-right">Next>></a>
<p class="pull-right" style="white-space:pre;"> </p>
<a href="#" id="loadPrev" class="pull-right"><<Previous</a>
</div>
<div id="loadingContainer" class="text-center" style="margin-top: 100px; padding-bottom: 100px"></div>
<div class="table-responsive">
<table id="trackingtable" class="table" style="visibility: hidden; font-weight: 400">
<col width="200">
<col width="150">
<col width="120">
<thead>
<tr>
<th>Title</th>
<th>Tracking Number</th>
<th>Scanned</th>
<th>Date/Time</th>
<th>Signature</th>
<th></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<div id="qrholder" style="display:none">
<a id="qrjpegDownload" class="btn btn-success btn-xs" href="imgData" target="_blank" download="image.jpg">QR JPEG</a>
</div>
<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src = "js/bootstrap.js"></script>
<script src="js/jquery.qrcode.min.js" type="text/javascript"></script>
<script src = "js/spin.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
Parse.initialize("SN9RAjbHn5ofcwqjshAYG0jRZnxQrMgZ6Xj3rJWh", "HX9VdqSqHXGxBQqXMBFBCASVLUiWrkAC2WPI1Pcb");
</script>
<script type = "text/javascript">
var qrid_results_saved = new Array();
var qrlog_results_replies = 0;
var spinner = null;
var currentUser = Parse.User.current();
//Pagination Variables //
var totalqr = 0;
var loadIndex = 0;
var rowsPerPage = 50;
var rowsOnCurrentPage = 0;
$(document).ready(function(){
if (currentUser) {
console.log(currentUser.get("full_name"));
$("#login").html(currentUser.get("full_name"));
buildTable(currentUser, loadIndex);
}
else {
window.location = "index.html";
}
});
function buildTable(currentUser, startIndex) {
$('#tableControls').hide();
$('#trackingtable').css("visibility","hidden");
$('table tbody').remove();
startSpinner();
var QrUrl = Parse.Object.extend("qr_url");
var qr_query = new Parse.Query(QrUrl);
qr_query.equalTo("createdBy", currentUser);
qr_query.include("createdBy");
qr_query.descending("createdAt")
qr_query.skip(startIndex);
qr_query.limit(rowsPerPage);
qr_query.count({
success: function(count) {
totalqr = count;
// Hide Table Controls //
console.log(startIndex);
if ((totalqr-startIndex) <= rowsPerPage) {
$('#loadNext').hide();
}
else {
$('#loadNext').show();
}
if (startIndex == 0) {
$('#loadPrev').hide();
}
else {
$('#loadPrev').show()
}
}
});
qr_query.find({
success: function(qrid_results) {
qrid_results_saved = qrid_results;
qrlog_results_replies = 0;
var QrLogger = Parse.Object.extend("qr_logger");
var qrlog_query = new Parse.Query(QrLogger);
qrlog_query.descending("createdAt");
qrlog_query.include("createdBy");
qrlog_query.include("qrid");
for (var i = 0; i < qrid_results.length; i++) {
qrlog_query.equalTo("qrid", qrid_results_saved[i]);
qrlog_query.find({
success: logQueryCallback,
error: function(result, error){console.log(error)}
});
}
},
error: function(result, error) {console.log(error)}
});
}
function logQueryCallback(qrlog_results) {
qrlog_results_replies++;
// If log data exists, then: //
if (qrlog_results.length > 0) {
// Match qrid entry with qr log entry, to add property containing log data //
for (var j = 0; j < qrid_results_saved.length; j++) {
if (qrid_results_saved[j].id === qrlog_results[0].get("qrid").id) {
qrid_results_saved[j].logs = qrlog_results;
break;
}
}
}
// Check when #(log query replies) = #(qrid entry calls), synchronous functions //
if (qrlog_results_replies === qrid_results_saved.length) {
$('#loadingContainer').data('spinner').stop();
$('#loadingContainer').hide();
$('#trackingtable').css("visibility", "visible");
$('#tableControls').show();
var htmlContent = '';
for (var i = 0; i < qrid_results_saved.length; i++) {
// Define tool tip //
var toolTip;
if (qrid_results_saved[i].get("message") != '' && qrid_results_saved[i].get("message") != undefined) {
toolTip = "class='hasTooltip' message='"+qrid_results_saved[i].get("message") + "'>";
}
else {
toolTip = '>';
}
htmlContent="<tbody><tr><td style='word-wrap:break-word'" + toolTip +qrid_results_saved[i].get("title") + "</td><td><a href=''>"+qrid_results_saved[i].id+"</a></td><td class='text-center'><span class='glyphicon glyphicon-minus'/></td><td>"+qrid_results_saved[i].createdAt.toDateString()+" | " +qrid_results_saved[i].createdAt.toLocaleTimeString()+"</td><td>"+qrid_results_saved[i].get("createdBy").get("full_name")+"</td><td><span class='glyphicon glyphicon-trash trash-bin'></td></tr></tbody>";
$('#trackingtable').append(htmlContent);
if (qrid_results_saved[i].logs) {
for (var j = 0; j < qrid_results_saved[i].logs.length; j++) {
var qrlog_entry = qrid_results_saved[i].logs[j];
var dated = qrlog_entry.updatedAt.toDateString()+" | "+qrlog_entry.updatedAt.toLocaleTimeString();
try {
var user_id = qrlog_entry.get("createdBy").get("full_name");
}
catch(err) {
user_id="Unknown Scanner";
}
htmlContent="<tr style='color:green'><td>"+"</td><td></td><td>"+"Scanned"+"</td><td>"+dated+"</td><td>"+user_id+"</td><td></td></tr>";
$('#trackingtable > tbody:last').append(htmlContent);
}
}
}
loadTableCompletion();
}
}
function loadTableCompletion() {
rowsOnCurrentPage = $('table tbody').length;
// Delete Specifc Rows & Data //
$('table tr>td:nth-child(6)>span').click(function() {
var rowData = $(this).parent().parent();
var trackingNumber = rowData.find('td:nth-child(2)').text();
var deleteConfirm = confirm("Are you sure want to delete this tracking entry?");
if (deleteConfirm == true) {
rowData.parent().find('tr').fadeOut();
deleteQrId(trackingNumber);
rowsOnCurrentPage--;
}
});
// Regenerate and Download QR Jpeg on Click //
$('table tr').find('td:nth-child(2)').click(function() {
var trackingNumber = $(this).text();
console.log(trackingNumber);
$('#qrholder').empty();
$('#qrholder').qrcode("markkirzon.altervista.org/scan.html?id=" + trackingNumber);
var imgData = document.getElementById('qr').toDataURL("image/jpeg");
$(this).find('a').attr('target', "_blank");
$(this).find('a').attr('download',"image.jpg");
$(this).find('a').attr('href', imgData);
});
// Hover highlight effect //
$('table tbody').mouseover(function(){
$(this).addClass('table-hover');
});
$('table tbody').mouseout(function(){
$(this).removeClass('table-hover');
});
// Group batches //
// Group scans with creates //
$('table tbody').find('tr:contains("Scanned")').hide();
var numberScans;
for (var i = 0; i < $('table tbody').length; i++) {
var numberScans = $('table').find('tbody')[i].children.length - 1;
if (numberScans >= 1) {
$('table tbody').eq(i).find('tr:first>td:nth-child(3)').append(numberScans);
$('table tbody').eq(i).find('tr:first>td:nth-child(3)>span').toggleClass('glyphicon-minus glyphicon-chevron-right');
$('table tbody').eq(i).find('tr:first>td:nth-child(3)').css('cursor','pointer')
}
}
$('table tr>td:nth-child(3)').click(function() {
var test = $(this).parent().parent();
if($(test).find('tr').length > 1) {
$(test).find('tr:gt(0)').toggle();
}
$(test).find('tr:first>td:nth-child(3)>span').toggleClass('glyphicon glyphicon-chevron-right glyphicon glyphicon-chevron-down');
});
} // *loadTableCompletion* //
// Delete QR id entry from Parse //
function deleteQrId(trackingNumber) {
var QrUrl = Parse.Object.extend("qr_url");
var qr_query = new Parse.Query(QrUrl);
qr_query.get(trackingNumber, {
success: function(qridDelete) {
var QrLogger = Parse.Object.extend("qr_logger");
var qrlog_query = new Parse.Query(QrLogger);
qrlog_query.equalTo("qrid",qridDelete);
qrlog_query.find({
success: function(logresults) {
for (var i = 0; i < logresults.length; i++) {
logresults[i].destroy();
}
qridDelete.destroy();
},
error: function(result, error){
console.log('error in qrlog_query delete')
}
});
}
});
}
// Delete all QR id entries from Parse //
function deleteQrAll() {
var QrUrl = Parse.Object.extend("qr_url");
var qr_query = new Parse.Query(QrUrl);
qr_query.find(currentUser, {
success: function(qridDelete) {
qridDelete.destroy();
}
});
}
// Loading Image while waiting for table //
function startSpinner() {
$('#loadingContainer').empty();
$('#loadingContainer').show();
var opts = {
lines: 15, // The number of lines to draw
length: 40, // The length of each line
width: 11, // The line thickness
radius: 0, // The radius of the inner circle
corners: 0.7, // Corner roundness (0..1)
rotate: 32, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#1990d5', // #rgb or #rrggbb or array of colors
speed: 1.2, // Rounds per second
trail: 56, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: 'auto', // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};
var target = document.getElementById('loadingContainer');
var spinner = new Spinner(opts).spin(target);
$(target).data('spinner', spinner);
}
$(document).ready(function() {
$('#logout').click(function() {
Parse.User.logOut();
window.location.href="index.html"
});
// Load Next & Previous Pages //
$('#loadNext').click(function() {
loadIndex += rowsOnCurrentPage;
buildTable(currentUser, loadIndex);
});
$('#loadPrev').click(function() {
loadIndex -= rowsPerPage;
if (loadIndex < 0) {loadIndex = 0};
buildTable(currentUser, loadIndex);
});
});
</script>
</body>
</html>