update current room
parent
af8e820c8e
commit
a7d86d9077
|
|
@ -14,6 +14,23 @@ function httpGetAsync(theUrl, callback, failCallback) {
|
||||||
xmlHttp.send(null);
|
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) {
|
function getCookie(cname) {
|
||||||
let name = cname + "=";
|
let name = cname + "=";
|
||||||
let decodedCookie = decodeURIComponent(document.cookie);
|
let decodedCookie = decodeURIComponent(document.cookie);
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,10 @@
|
||||||
|
|
||||||
|
|
||||||
<div id="headset_details" style="display: none;">
|
<div id="headset_details" style="display: none;">
|
||||||
<div class="panel">
|
<div class="panel card">
|
||||||
<div class="panel-header text-center">
|
<div class="panel-header text-center">
|
||||||
<figure class="avatar avatar-lg"><img src="static/favicon/android-chrome-192x192.png" alt="Avatar"></figure>
|
<figure class="avatar avatar-lg"><img src="/static/favicons/android-chrome-192x192.png"
|
||||||
|
alt="Avatar"></figure>
|
||||||
<div class="panel-title h5 mt-10">Headset Info</div>
|
<div class="panel-title h5 mt-10">Headset Info</div>
|
||||||
<div class="panel-subtitle hw_id">---</div>
|
<div class="panel-subtitle hw_id">---</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -51,8 +52,8 @@
|
||||||
<input class="btn" type="text" id="current_room" placeholder="----">
|
<input class="btn" type="text" id="current_room" placeholder="----">
|
||||||
</div>
|
</div>
|
||||||
<div class="tile-action">
|
<div class="tile-action">
|
||||||
<button class="btn btn-link btn-action btn-lg tooltip tooltip-left"
|
<button class="btn btn-link btn-action btn-lg tooltip tooltip-left" id="set_room_id"
|
||||||
data-tooltip="Set Room ID"><i class="icon icon-send"></i></button>
|
data-tooltip="Set Room ID"><i class="icon icon-check"></i></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tile tile-centered">
|
<div class="tile tile-centered">
|
||||||
|
|
@ -67,6 +68,9 @@
|
||||||
<div class="tile-subtitle last_used">---</div>
|
<div class="tile-subtitle last_used">---</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -81,6 +85,8 @@
|
||||||
let headset_details = document.getElementById('headset_details');
|
let headset_details = document.getElementById('headset_details');
|
||||||
let hw_id_field = document.getElementById('hw_id');
|
let hw_id_field = document.getElementById('hw_id');
|
||||||
let failure = document.getElementById('failure');
|
let failure = document.getElementById('failure');
|
||||||
|
let set_room_id = document.getElementById('set_room_id');
|
||||||
|
let current_room = document.getElementById('current_room');
|
||||||
|
|
||||||
|
|
||||||
// check cookie
|
// check cookie
|
||||||
|
|
@ -91,7 +97,7 @@
|
||||||
httpGetAsync('/api/get_headset_details/' + hw_id, (resp) => {
|
httpGetAsync('/api/get_headset_details/' + hw_id, (resp) => {
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
let respData = JSON.parse(resp);
|
let respData = JSON.parse(resp);
|
||||||
|
|
||||||
writeClass('hw_id', respData['hw_data']);
|
writeClass('hw_id', respData['hw_data']);
|
||||||
writeClass('current_room', respData['current_room']);
|
writeClass('current_room', respData['current_room']);
|
||||||
writeClass('date_created', respData['date_created']);
|
writeClass('date_created', respData['date_created']);
|
||||||
|
|
@ -102,6 +108,19 @@
|
||||||
failure.style.display = "block";
|
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 {
|
} else {
|
||||||
window.location.href = "/pair";
|
window.location.href = "/pair";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue