Sync both clan lists.
This commit is contained in:
@@ -26,19 +26,16 @@
|
||||
const deleteClanModalBS = new bootstrap.Modal('#deleteClanModal');
|
||||
if (deleteClanModal) {
|
||||
deleteClanModal.addEventListener('show.bs.modal', event => {
|
||||
const button = event.relatedTarget;
|
||||
const clanListId = button.getAttribute('data-bs-list');
|
||||
const clanList = document.querySelector(clanListId);
|
||||
const selectedClan = clanList.options[clanList.selectedIndex].text;
|
||||
const [clanList, otherClanList] = getClanLists(event);
|
||||
|
||||
const selectedClan = clanList.options[clanList.selectedIndex].text;
|
||||
const modalBodyInput = deleteClanModal.querySelector('#clan');
|
||||
modalBodyInput.innerText = selectedClan;
|
||||
|
||||
const submitButton = deleteClanModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function () {
|
||||
const button = event.relatedTarget;
|
||||
const clanListId = button.getAttribute('data-bs-list');
|
||||
const clanList = document.querySelector(clanListId);
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
|
||||
const clanId = parseInt(clanList.value);
|
||||
|
||||
@@ -50,9 +47,19 @@
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
clanList.removeChild(clanList.children[clanList.selectedIndex]);
|
||||
const clanToRemove = clanList.children[clanList.selectedIndex];
|
||||
const clanIndex = clanToRemove.index;
|
||||
clanList.removeChild(clanToRemove);
|
||||
clanList.selectedIndex = 0;
|
||||
clanList.dispatchEvent(new Event('change'));
|
||||
|
||||
const lastOtherIndex = otherClanList.selectedIndex;
|
||||
otherClanList.children.item(clanIndex).remove();
|
||||
if (lastOtherIndex === clanIndex) {
|
||||
otherClanList.selectedIndex = 0;
|
||||
otherClanList.dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
deleteClanModalBS.hide();
|
||||
} else
|
||||
throw new Error(response.error)
|
||||
|
||||
Reference in New Issue
Block a user