mirror of
https://github.com/zyphlar/doorlock.git
synced 2024-04-03 21:36:03 +00:00
fine tuning ajax timing, naming, and start script
This commit is contained in:
parent
aa57b26a8b
commit
31d059972c
|
@ -6,22 +6,26 @@ $(function(){
|
||||||
}, 20000);
|
}, 20000);
|
||||||
|
|
||||||
$("#rfid").keydown(function(event){
|
$("#rfid").keydown(function(event){
|
||||||
// cancel enter keys
|
// prevent enter key from submitting form; we want AJAX if possible
|
||||||
if (event.keyCode === 13){
|
if (event.keyCode === 13){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}).keyup(function(event){
|
||||||
// store value
|
// store value
|
||||||
value = $("#rfid").val();
|
value = $("#rfid").val();
|
||||||
|
|
||||||
// start processing after the first few chars
|
// start processing after the enter key
|
||||||
if (value.length >= 5) {
|
if (event.keyCode === 13) {
|
||||||
// wait to send the request for a sec to let them finish typing
|
// wait to send the request for a sec to let them finish typing
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
// clear input box
|
// clear input box
|
||||||
$("#rfid").val(null);
|
$("#rfid").val(null);
|
||||||
// post value to server
|
// post value to server
|
||||||
loading(true);
|
loading(true);
|
||||||
|
if (!window.checkinLoading) {
|
||||||
|
// use global var to prevent simultaneous posts
|
||||||
|
window.checkinLoading = true;
|
||||||
|
console.log("Checking in...");
|
||||||
$.post("/checkin", {"rfid":value}, function(data){
|
$.post("/checkin", {"rfid":value}, function(data){
|
||||||
console.log(data);
|
console.log(data);
|
||||||
if (data.hasOwnProperty("success")) {
|
if (data.hasOwnProperty("success")) {
|
||||||
|
@ -37,7 +41,11 @@ $(function(){
|
||||||
error();
|
error();
|
||||||
}).always(function(){
|
}).always(function(){
|
||||||
loading(false);
|
loading(false);
|
||||||
|
window.checkinLoading = false;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Already checking in; canceled.");
|
||||||
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -61,19 +69,25 @@ function reset(){
|
||||||
|
|
||||||
function success(name){
|
function success(name){
|
||||||
reset();
|
reset();
|
||||||
|
setTimeout(function(){
|
||||||
$("#name").text(name);
|
$("#name").text(name);
|
||||||
$("#success").removeClass("dn");
|
$("#success").removeClass("dn");
|
||||||
setTimeout(function(){ reset(); }, 5000);
|
setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY)
|
||||||
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
function failure(){
|
function failure(){
|
||||||
reset();
|
reset();
|
||||||
|
setTimeout(function(){
|
||||||
$("#failure").removeClass("dn");
|
$("#failure").removeClass("dn");
|
||||||
setTimeout(function(){ reset(); }, 5000);
|
setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY)
|
||||||
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(){
|
function error(){
|
||||||
reset();
|
reset();
|
||||||
|
setTimeout(function(){
|
||||||
$("#error").removeClass("dn");
|
$("#error").removeClass("dn");
|
||||||
setTimeout(function(){ reset(); }, 5000);
|
setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY)
|
||||||
|
}, 250);
|
||||||
}
|
}
|
|
@ -26,7 +26,7 @@ module.exports = (req, res) => {
|
||||||
function reponse(req,res,path,success,name=null) {
|
function reponse(req,res,path,success,name=null) {
|
||||||
console.log(req.get('accept'));
|
console.log(req.get('accept'));
|
||||||
if(/application\/json/.test(req.get('accept'))) {
|
if(/application\/json/.test(req.get('accept'))) {
|
||||||
res.json({"success":success, "path":path})
|
res.json({"success":success, "path":path, "name":name})
|
||||||
} else {
|
} else {
|
||||||
res.redirect(path)
|
res.redirect(path)
|
||||||
}
|
}
|
||||||
|
|
2
start.sh
2
start.sh
|
@ -2,4 +2,4 @@
|
||||||
~/.nvm/versions/node/v10.6.0/bin/forever start --workingDir /home/pi/doorlock /home/pi/doorlock/src/server.js
|
~/.nvm/versions/node/v10.6.0/bin/forever start --workingDir /home/pi/doorlock /home/pi/doorlock/src/server.js
|
||||||
echo "Loading Browser..."
|
echo "Loading Browser..."
|
||||||
sleep 5
|
sleep 5
|
||||||
chromium-browser --kiosk localhost:3000
|
chromium-browser --incognito --kiosk --app=http://localhost:3000
|
||||||
|
|
Loading…
Reference in New Issue
Block a user