diff --git a/data/static/setup.js b/data/static/setup.js index 7bff360..b018425 100644 --- a/data/static/setup.js +++ b/data/static/setup.js @@ -104,36 +104,55 @@ var jfValid = false document.getElementById('jfTestButton').onclick = function() { var testButton = document.getElementById('jfTestButton'); var nextButton = document.getElementById('jfNextButton'); - testButton.disabled = true; - testButton.innerHTML = - '' + - 'Testing...'; - nextButton.classList.add('disabled'); - nextButton.setAttribute('aria-disabled', 'true'); var jfData = {}; jfData['jfHost'] = document.getElementById('jfHost').value; jfData['jfUser'] = document.getElementById('jfUser').value; jfData['jfPassword'] = document.getElementById('jfPassword').value; - var req = new XMLHttpRequest(); - req.open("POST", "/testJF", true); - req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); - req.responseType = 'json'; - req.onreadystatechange = function() { - if (this.readyState == 4) { - testButton.disabled = false; - testButton.className = ''; - if (this.response['success'] == true) { - testButton.classList.add('btn', 'btn-success'); - testButton.textContent = 'Success'; - nextButton.classList.remove('disabled'); - nextButton.setAttribute('aria-disabled', 'false'); - } else { - testButton.classList.add('btn', 'btn-danger'); - testButton.textContent = 'Failed'; + let valid = true; + for (val in jfData) { + if (jfData[val] == "") { + valid = false; + } + } + if (!valid) { + if (!testButton.classList.contains('btn-danger')) { + testButton.classList.add('btn-danger'); + testButton.textContent = 'Fill out fields above.'; + setTimeout(function() { + if (testButton.classList.contains('btn-danger')) { + testButton.classList.remove('btn-danger'); + testButton.textContent = 'Test'; + } + }, 2000); + } + } else { + testButton.disabled = true; + testButton.innerHTML = + '' + + 'Testing...'; + nextButton.classList.add('disabled'); + nextButton.setAttribute('aria-disabled', 'true'); + var req = new XMLHttpRequest(); + req.open("POST", "/testJF", true); + req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + req.responseType = 'json'; + req.onreadystatechange = function() { + if (this.readyState == 4) { + testButton.disabled = false; + testButton.className = ''; + if (this.response['success'] == true) { + testButton.classList.add('btn', 'btn-success'); + testButton.textContent = 'Success'; + nextButton.classList.remove('disabled'); + nextButton.setAttribute('aria-disabled', 'false'); + } else { + testButton.classList.add('btn', 'btn-danger'); + testButton.textContent = 'Failed'; + }; }; - }; - }; - req.send(JSON.stringify(jfData)); + }; + req.send(JSON.stringify(jfData)); + } }; document.getElementById('submitButton').onclick = function() { diff --git a/data/templates/setup.html b/data/templates/setup.html index dc7cda2..57d2cd7 100644 --- a/data/templates/setup.html +++ b/data/templates/setup.html @@ -3,12 +3,10 @@ - - - - - - + + + +