2018-09-01 02:15:00 +00:00
|
|
|
$(function(){
|
|
|
|
// refocus and clear the input box every 20sec
|
|
|
|
setInterval(function(){
|
|
|
|
$("#rfid").focus();
|
|
|
|
$("#rfid").val(null);
|
|
|
|
}, 20000);
|
|
|
|
|
|
|
|
$("#rfid").keydown(function(event){
|
2018-09-01 19:56:18 +00:00
|
|
|
// prevent enter key from submitting form; we want AJAX if possible
|
2018-09-01 02:15:00 +00:00
|
|
|
if (event.keyCode === 13){
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-01 19:56:18 +00:00
|
|
|
}).keyup(function(event){
|
2018-09-01 02:15:00 +00:00
|
|
|
// store value
|
|
|
|
value = $("#rfid").val();
|
|
|
|
|
2018-09-01 19:56:18 +00:00
|
|
|
// start processing after the enter key
|
|
|
|
if (event.keyCode === 13) {
|
2018-09-01 02:15:00 +00:00
|
|
|
// wait to send the request for a sec to let them finish typing
|
|
|
|
setTimeout(function(){
|
|
|
|
// clear input box
|
|
|
|
$("#rfid").val(null);
|
|
|
|
// post value to server
|
|
|
|
loading(true);
|
2018-09-01 19:56:18 +00:00
|
|
|
if (!window.checkinLoading) {
|
|
|
|
// use global var to prevent simultaneous posts
|
|
|
|
window.checkinLoading = true;
|
|
|
|
console.log("Checking in...");
|
|
|
|
$.post("/checkin", {"rfid":value}, function(data){
|
|
|
|
console.log(data);
|
|
|
|
if (data.hasOwnProperty("success")) {
|
|
|
|
if (data.success) {
|
|
|
|
success(data.name);
|
|
|
|
} else {
|
|
|
|
failure();
|
|
|
|
}
|
2018-09-01 02:15:00 +00:00
|
|
|
} else {
|
2018-09-01 22:59:11 +00:00
|
|
|
error(data);
|
2018-09-01 02:15:00 +00:00
|
|
|
}
|
2018-09-01 22:59:11 +00:00
|
|
|
}, "json").fail(function(res){
|
|
|
|
error(res.responseText);
|
2018-09-01 19:56:18 +00:00
|
|
|
}).always(function(){
|
|
|
|
loading(false);
|
|
|
|
window.checkinLoading = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log("Already checking in; canceled.");
|
|
|
|
}
|
2018-09-01 02:15:00 +00:00
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function loading(loading){
|
|
|
|
if (loading) {
|
|
|
|
$("#loading").removeClass("dn");
|
|
|
|
} else {
|
|
|
|
$("#loading").addClass("dn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset(){
|
|
|
|
$("#name").text(null);
|
|
|
|
$("#failure").addClass("dn");
|
|
|
|
$("#success").addClass("dn");
|
|
|
|
$("#error").addClass("dn");
|
2018-09-01 22:59:11 +00:00
|
|
|
$("#errormessage").text("Something went wrong with the card reader.");
|
2018-09-01 02:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function success(name){
|
|
|
|
reset();
|
2018-09-01 19:56:18 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
$("#name").text(name);
|
|
|
|
$("#success").removeClass("dn");
|
|
|
|
setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY)
|
|
|
|
}, 250);
|
2018-09-01 02:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function failure(){
|
|
|
|
reset();
|
2018-09-01 19:56:18 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
$("#failure").removeClass("dn");
|
|
|
|
setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY)
|
|
|
|
}, 250);
|
2018-09-01 02:15:00 +00:00
|
|
|
}
|
|
|
|
|
2018-09-01 22:59:11 +00:00
|
|
|
function error(msg){
|
|
|
|
console.log(msg);
|
2018-09-01 02:15:00 +00:00
|
|
|
reset();
|
2018-09-01 19:56:18 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
$("#error").removeClass("dn");
|
2018-09-01 22:59:11 +00:00
|
|
|
if (msg) {
|
|
|
|
$("#errormessage").text(msg);
|
|
|
|
}
|
2018-09-01 19:56:18 +00:00
|
|
|
setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY)
|
|
|
|
}, 250);
|
2018-09-01 02:15:00 +00:00
|
|
|
}
|