Optimize all modals (fetching). Implement add-player modal.
This commit is contained in:
@@ -57,26 +57,37 @@
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
const opt = document.createElement('option');
|
||||
opt.innerText = "[" + clanTag.value + "]" + " " + clanName.value;
|
||||
opt.value = response.json()['ID'];
|
||||
.then(() => {
|
||||
const lastIndex = otherClanList.selectedIndex;
|
||||
|
||||
clanList.appendChild(opt.cloneNode(true));
|
||||
clanList.selectedIndex = clanList.children.length - 1;
|
||||
clanList.dispatchEvent(new Event('change'));
|
||||
fetch('/clans_html')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
clanList.innerHTML = data;
|
||||
otherClanList.innerHTML = data;
|
||||
|
||||
const lastIndex = otherClanList.selectedIndex;
|
||||
otherClanList.appendChild(opt);
|
||||
otherClanList.selectedIndex = lastIndex;
|
||||
clanList.selectedIndex = clanList.children.length - 1;
|
||||
otherClanList.selectedIndex = lastIndex;
|
||||
|
||||
addClanModalBS.hide();
|
||||
clanName.value = "";
|
||||
clanTag.value = "";
|
||||
keepUpdated.checked = false;
|
||||
} else
|
||||
throw new Error(response.error)
|
||||
clanList.dispatchEvent(new Event('change'));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('There has been a problem with your fetch operation:', error);
|
||||
});
|
||||
|
||||
|
||||
addClanModalBS.hide();
|
||||
clanName.value = "";
|
||||
clanTag.value = "";
|
||||
keepUpdated.checked = false;
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(error)
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user