Replace jquery ajax in setup.js

This commit is contained in:
Harvey Tindall 2020-07-07 20:10:27 +01:00
parent 94e69ad090
commit 71f05f2348
2 changed files with 26 additions and 24 deletions

View File

@ -22,4 +22,4 @@ function serializeForm(id) {
}; };
}; };
return formData; return formData;
}; };

View File

@ -13,6 +13,7 @@ for (var i = 0; i < authRadios.length; i++) {
checkAuthRadio(); checkAuthRadio();
}); });
}; };
function checkEmailRadio() { function checkEmailRadio() {
document.getElementById('emailNextButton').href = '#page-5'; document.getElementById('emailNextButton').href = '#page-5';
document.getElementById('valBackButton').href = '#page-7'; document.getElementById('valBackButton').href = '#page-7';
@ -35,6 +36,7 @@ for (var i = 0; i < emailRadios.length; i++) {
checkEmailRadio(); checkEmailRadio();
}); });
}; };
function checkSSL() { function checkSSL() {
var label = document.getElementById('emailSSL_TLSLabel'); var label = document.getElementById('emailSSL_TLSLabel');
if (document.getElementById('emailSSL_TLS').checked) { if (document.getElementById('emailSSL_TLS').checked) {
@ -101,16 +103,15 @@ document.getElementById('jfTestButton').onclick = function() {
jfData['jfHost'] = document.getElementById('jfHost').value; jfData['jfHost'] = document.getElementById('jfHost').value;
jfData['jfUser'] = document.getElementById('jfUser').value; jfData['jfUser'] = document.getElementById('jfUser').value;
jfData['jfPassword'] = document.getElementById('jfPassword').value; jfData['jfPassword'] = document.getElementById('jfPassword').value;
$.ajax('/testJF', { var req = new XMLHttpRequest();
type : 'POST', req.open("POST", "/testJF", true);
dataType : 'json', req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
contentType : 'application/json', req.responseType = 'json';
data : JSON.stringify(jfData), req.onreadystatechange = function() {
complete: function(response) { if (this.readyState == 4) {
testButton.disabled = false; testButton.disabled = false;
testButton.className = ''; testButton.className = '';
var success = response['responseJSON']['success']; if (this.response['success'] == true) {
if (success == true) {
testButton.classList.add('btn', 'btn-success'); testButton.classList.add('btn', 'btn-success');
testButton.textContent = 'Success'; testButton.textContent = 'Success';
nextButton.classList.remove('disabled'); nextButton.classList.remove('disabled');
@ -118,9 +119,10 @@ document.getElementById('jfTestButton').onclick = function() {
} else { } else {
testButton.classList.add('btn', 'btn-danger'); testButton.classList.add('btn', 'btn-danger');
testButton.textContent = 'Failed'; testButton.textContent = 'Failed';
} };
} };
}); };
req.send(JSON.stringify(jfData));
}; };
document.getElementById('submitButton').onclick = function() { document.getElementById('submitButton').onclick = function() {
@ -158,7 +160,7 @@ document.getElementById('submitButton').onclick = function() {
if (document.getElementById('emailDisabledRadio').checked) { if (document.getElementById('emailDisabledRadio').checked) {
config['password_resets']['enabled'] = 'false'; config['password_resets']['enabled'] = 'false';
config['invite_emails']['enabled'] = 'false'; config['invite_emails']['enabled'] = 'false';
} else { } else {
if (document.getElementById('emailSMTPRadio').checked) { if (document.getElementById('emailSMTPRadio').checked) {
if (document.getElementById('emailSSL_TLS').checked) { if (document.getElementById('emailSSL_TLS').checked) {
config['smtp']['encryption'] = 'ssl_tls'; config['smtp']['encryption'] = 'ssl_tls';
@ -211,24 +213,24 @@ document.getElementById('submitButton').onclick = function() {
config['password_validation']['number'] = document.getElementById('valNumber').value; config['password_validation']['number'] = document.getElementById('valNumber').value;
config['password_validation']['special'] = document.getElementById('valSpecial').value; config['password_validation']['special'] = document.getElementById('valSpecial').value;
} else { } else {
config['password_validation']['enabled'] = 'false'; config['password_validation']['enabled'] = 'false';
}; };
// Page 9: Messages // Page 9: Messages
config['ui']['contact_message'] = document.getElementById('msgContact').value; config['ui']['contact_message'] = document.getElementById('msgContact').value;
config['ui']['help_message'] = document.getElementById('msgHelp').value; config['ui']['help_message'] = document.getElementById('msgHelp').value;
config['ui']['success_message'] = document.getElementById('msgSuccess').value; config['ui']['success_message'] = document.getElementById('msgSuccess').value;
console.log(config); // Send it
$.ajax('/modifyConfig', { var req = new XMLHttpRequest();
type : 'POST', req.open("POST", "/modifyConfig", true);
dataType : 'json', req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
contentType : 'application/json', req.responseType = 'json';
data : JSON.stringify(config), req.onreadystatechange = function() {
complete: function(response) { if (this.readyState == 4) {
submitButton.disabled = false; submitButton.disabled = false;
submitButton.className = ''; submitButton.className = '';
submitButton.classList.add('btn', 'btn-success'); submitButton.classList.add('btn', 'btn-success');
submitButton.textContent = 'Success'; submitButton.textContent = 'Success';
} };
}); };
req.send(JSON.stringify(config));
}; };