prevent second requests when the relay is still active

This commit is contained in:
Will Bradley 2018-09-01 17:44:08 -07:00
parent 554b5e7264
commit bfc76199bc
No known key found for this signature in database
GPG Key ID: 42BAE225DDDB7093

View File

@ -1,8 +1,9 @@
$(function(){ $(function(){
// refocus and clear the input box every 20sec // refocus and clear the input box and relay every 20sec for failsafe
setInterval(function(){ setInterval(function(){
$("#rfid").focus(); $("#rfid").focus();
$("#rfid").val(null); $("#rfid").val(null);
window.relayActivated = false;
}, 20000); }, 20000);
$("#rfid").keydown(function(event){ $("#rfid").keydown(function(event){
@ -22,7 +23,7 @@ $(function(){
$("#rfid").val(null); $("#rfid").val(null);
// post value to server // post value to server
loading(true); loading(true);
if (!window.checkinLoading) { if (!window.checkinLoading && !window.relayActivated) {
// use global var to prevent simultaneous posts // use global var to prevent simultaneous posts
window.checkinLoading = true; window.checkinLoading = true;
console.log("Checking in..."); console.log("Checking in...");
@ -31,6 +32,7 @@ $(function(){
if (data.hasOwnProperty("success")) { if (data.hasOwnProperty("success")) {
if (data.success) { if (data.success) {
success(data.name); success(data.name);
window.relayActivated = true;
} else { } else {
failure(); failure();
} }
@ -66,6 +68,7 @@ function reset(){
$("#success").addClass("dn"); $("#success").addClass("dn");
$("#error").addClass("dn"); $("#error").addClass("dn");
$("#errormessage").text("Something went wrong with the card reader."); $("#errormessage").text("Something went wrong with the card reader.");
loading(false);
} }
function success(name){ function success(name){
@ -73,7 +76,11 @@ function success(name){
setTimeout(function(){ setTimeout(function(){
$("#name").text(name); $("#name").text(name);
$("#success").removeClass("dn"); $("#success").removeClass("dn");
setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY) setTimeout(function(){
reset();
// this is the only time when the relay is reset, besides the 20-sec reset
window.relayActivated = false;
}, 6000); // 6000 to match door.js(const DELAY)
}, 250); }, 250);
} }