From a7d86d907712e05fdc60caf36a547e798bed8842 Mon Sep 17 00:00:00 2001 From: Anton Franzluebbers Date: Fri, 15 Oct 2021 23:56:07 -0400 Subject: [PATCH] update current room --- velconnect/static/js/util.js | 17 +++++++++++++++++ velconnect/templates/index.jinja | 29 ++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/velconnect/static/js/util.js b/velconnect/static/js/util.js index b4877ff..3d94740 100644 --- a/velconnect/static/js/util.js +++ b/velconnect/static/js/util.js @@ -14,6 +14,23 @@ function httpGetAsync(theUrl, callback, failCallback) { xmlHttp.send(null); } + +function httpPostAsync(theUrl, data, callback, failCallback) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState == 4) { + if (xmlHttp.status == 200) { + callback(xmlHttp.responseText); + } else { + failCallback(xmlHttp.status); + } + } + } + xmlHttp.open("POST", theUrl, true); // true for asynchronous + http.setRequestHeader('Content-type', 'application/json'); + xmlHttp.send(data); +} + function getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); diff --git a/velconnect/templates/index.jinja b/velconnect/templates/index.jinja index fcab8cf..ae0e46b 100644 --- a/velconnect/templates/index.jinja +++ b/velconnect/templates/index.jinja @@ -38,9 +38,10 @@ +
+
+
@@ -81,6 +85,8 @@ let headset_details = document.getElementById('headset_details'); let hw_id_field = document.getElementById('hw_id'); let failure = document.getElementById('failure'); + let set_room_id = document.getElementById('set_room_id'); + let current_room = document.getElementById('current_room'); // check cookie @@ -91,7 +97,7 @@ httpGetAsync('/api/get_headset_details/' + hw_id, (resp) => { console.log(resp); let respData = JSON.parse(resp); - + writeClass('hw_id', respData['hw_data']); writeClass('current_room', respData['current_room']); writeClass('date_created', respData['date_created']); @@ -102,6 +108,19 @@ failure.style.display = "block"; }); + set_room_id.addEventListener('click', () => { + httpPostAsync('/api/set_headset_details/' + hw_id, + { + "current_room": current_room.value + }, + (resp) => { + console.log('success'); + }, + (status) => { + console.log('fail'); + }); + }); + } else { window.location.href = "/pair"; }