function getRequest (url) { console.log('making GET request to', 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 username or password'); } else { reject('request failed with status:' + xhttp.status); }; } }; xhttp.send(); }) } function postRequest (url, params) { console.log('making POST request to', url) 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('wrong username 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 = 1; var adder = 1; function addOne(){ var bars = '

|'; for (var i = 0; i < x; i++){ bars += ' | '; } bars += '

'; element.innerHTML = bars; if (x === size){ adder = -1; } else if ( x === 0){ adder = 1; } x += adder; }; setInterval(addOne, 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