function getRequest (url) { return new Promise((resolve, reject) => { let xhttp = new XMLHttpRequest(); xhttp.open('GET', url, true); xhttp.responseType = 'json'; xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 ) { if ( xhttp.status == 200) { resolve(xhttp.response); } else if (xhttp.status == 401) { reject('Wrong channel name or password'); } else { reject('request failed with status:' + xhttp.status); }; } }; xhttp.send(); }) } function postRequest (url, params) { return new Promise((resolve, reject) => { let xhttp = new XMLHttpRequest(); xhttp.open('POST', url, true); xhttp.responseType = 'json'; xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 ) { if ( xhttp.status == 200) { resolve(xhttp.response); } else if (xhttp.status == 401) { reject( new AuthenticationError('Wrong channel name or password')); } else { reject('request failed with status:' + xhttp.status); }; } }; xhttp.send(params); }) } function toggleSection(event){ event.preventDefault(); var dataSet = event.target.dataset; var status = dataSet.open; var masterElement = document.getElementById(event.target.id||event.srcElement.id); var slaveElement = document.getElementById(dataSet.slaveelementid); var closedLabel = dataSet.closedlabel; var openLabel = dataSet.openlabel; if (status === "false") { slaveElement.hidden = false; masterElement.innerText = openLabel; masterElement.dataset.open = "true"; } else { slaveElement.hidden = true; masterElement.innerText = closedLabel; masterElement.dataset.open = "false"; } } function createProgressBar(element, size){ var x = 0; var adder = 1; // create the bar holder & place it var barHolder = document.createElement('p'); for (var i = 0; i < size; i++) { const bar = document.createElement('span'); bar.innerText = '| '; bar.setAttribute('class', 'progress-bar progress-bar--inactive'); barHolder.appendChild(bar); } element.appendChild(barHolder); // get the bars const bars = document.getElementsByClassName('progress-bar'); // function to update the bars' classes function updateOneBar(){ // update the appropriate bar if (x > -1 && x < size){ if (adder === 1){ bars[x].setAttribute('class', 'progress-bar progress-bar--active'); } else { bars[x].setAttribute('class', 'progress-bar progress-bar--inactive'); } } // set x if (x === size){ adder = -1; } else if ( x === -1){ adder = 1; } // update the adder x += adder; }; // start updater setInterval(updateOneBar, 300); } function setCookie(key, value) { document.cookie = `${key}=${value}`; } function getCookie(cname) { const name = cname + "="; const decodedCookie = decodeURIComponent(document.cookie); const ca = decodedCookie.split(';'); for(let i = 0; i