1 var flask = "{{ url_for('hello', _external=True) }}"
3 var updateRemote = undefined;
6 console.log("hello from flask");
7 //sendJSON("{\"type\":\"empty\"}");
9 function update(id, msg) {
10 document.getElementById(id).innerHTML = msg;
13 function loadLocalStorage() {
15 if (localStorage.length) {
16 for (var i = 0; i < localStorage.length; i++) {
17 var value = localStorage.getItem(localStorage.key(i));
21 console.log("no json: " + value)
29 function hiddenUpdateRemote(json) {
30 var msg = JSON.parse(json);
32 //update("json", "json: " + JSON.stringify(msg))
40 "uid: " + msg.uid + "<br>" +
41 "card type: " + msg.card_type + "<br>" +
42 "uid size: " + msg.size + " bytes<br>" +
48 //update("json", "key: " + msg.key);
50 var flavor = getFlavor(msg.key);
58 ajax(msg.method, msg.route, msg.data, msg.id);
64 function loadRemote(string) {
65 var xhr = new XMLHttpRequest();
66 xhr.onreadystatechange = function() {
67 if (this.readyState == 4 && this.status == 200) {
68 update("remote", this.responseText);
69 updateRemote = hiddenUpdateRemote;
72 document.getElementById("local").style.display = "none";
76 xhr.open("GET", flask, true);
82 function ajax(method, route, data, id) {
83 var xhr = new XMLHttpRequest();
84 xhr.onreadystatechange = function() {
85 if (this.readyState == 4) {
86 if (this.status == 200) {
87 update(id, this.responseText);
89 updateRemote = undefined;
90 update("remote", "<center>Server offline...</center>");
91 document.getElementById("local").style.display = "block";
94 var fuck = JSON.stringify({
101 localStorage.setItem(now, fuck);
102 console.log(now + ": " + fuck);
107 xhr.open(method, flask + route, true);
108 xhr.withCredentials = true;
109 xhr.setRequestHeader("Content-type", "application/json");
110 if (method === "POST") {
120 ajax("POST", "login", id, "user");
122 document.getElementById("local").style.display = "none";
123 //timer = setTimeout(logout, 20000);
127 //clearTimeout(timer);
129 ajax("GET", "logout", "", "user");
131 document.getElementById("local").style.display = "block";
134 function renameUser() {
135 ajax("GET", "user/rename?name=" + document.getElementById("username").value, "", "user");
138 function getFlavor(letter) {
140 case "E": return "espresso";
141 case "C": return "cappuccino";
142 case "B": return "latte macchiato";
143 case "D": return "espresso lungo";
148 function addCoffee(flavor) {
149 var data = JSON.stringify({
150 time: new Date().toISOString(),
153 ajax("POST", "coffee/add", data, "user");
156 function sendLog(json) {
157 ajax("POST", "log", json, "log");