]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Improve the last commit
authorMichal Sojka <michal.sojka@cvut.cz>
Thu, 16 Aug 2018 09:46:55 +0000 (11:46 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 16 Aug 2018 09:51:14 +0000 (11:51 +0200)
- Move id_user variable to where other variables are defined and
  document it.
- Set its value in the login() function. All other activities related
  to logging in are in that function, so I don't see a reason, why
  this should be outside.
- Unset this variable in addCoffee() and logout(). We should not need
  it after these events.

templates/main.js

index 6d4fc866b457a117869e8079c8feb0d08007ba03..daca42ca24abaf2aa0201af60a5ad168d956c292 100644 (file)
@@ -7,6 +7,7 @@ var loggedIn = false;           // true after swiping the cards
 var timeToLogout = undefined;   // defined during logout countdown
 var logoutTimer;
 var reloadTimer = undefined;
+var id_user;                    // ID of the user who is to be accounted for the next coffee
 
 console.log("hello from flask");
 //sendJSON("{\"type\":\"empty\"}");
@@ -63,8 +64,6 @@ function updateUI()
     }
 }
 
-var id_user;
-
 function hiddenUpdateRemote(json) {
     var msg = JSON.parse(json);
 
@@ -82,7 +81,6 @@ function hiddenUpdateRemote(json) {
                 "sak: " + msg.sak
             );*/
             login(msg.uid);
-            id_user=msg.uid;
             break;
         case "keys":
             //update("json", "key: " + msg.key);
@@ -159,6 +157,7 @@ function ajax(method, route, data, id) {
 function login(id) {
     ajax("POST", "login", id, "user");
     loggedIn = true;
+    id_user = id;
     clearTimeout(logoutTimer);
     timeToLogout = undefined;
 }
@@ -167,6 +166,7 @@ function logout() {
     sendReset();
     ajax("GET", "logout", "", "user");
     loggedIn = false;
+    id_user = undefined;
     timeToLogout = undefined;
 }
 
@@ -205,6 +205,7 @@ function addCoffee(flavor) {
         ajax("POST", "coffee/add", data, "user");
         flavorChosen = flavor;
         loggedIn = false;
+        id_user = undefined;
         countingTimeLogout(10); //mean 10 seconds
     }
 }