Adds delete option
This commit is contained in:
parent
bfeb2a6e2a
commit
8388c2ccc6
6 changed files with 199 additions and 6 deletions
42
src/js/pages/keys/modals/delete.ts
Normal file
42
src/js/pages/keys/modals/delete.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import {getCurrentlySelectedList} from "../userlists";
|
||||
|
||||
export function init() {
|
||||
const modalElem = document.querySelector<HTMLDivElement>('#delete-list-modal');
|
||||
|
||||
if (!modalElem) {
|
||||
return;
|
||||
}
|
||||
|
||||
modalElem.addEventListener('show.bs.modal', () => {
|
||||
const listSelect = document.querySelector<HTMLSelectElement>('#list-select');
|
||||
const text = listSelect?.selectedOptions[0].text ?? '';
|
||||
|
||||
const listnameElem = modalElem.querySelector<HTMLSpanElement>('.list-name');
|
||||
if (!listnameElem) {
|
||||
return;
|
||||
}
|
||||
listnameElem.textContent = text;
|
||||
})
|
||||
|
||||
modalElem.querySelector<HTMLButtonElement>('.js--yes')
|
||||
?.addEventListener('click', async () => {
|
||||
const id = getCurrentlySelectedList();
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('id', id?.toString() ?? '-1');
|
||||
|
||||
const response = await fetch(
|
||||
`/api/web/keys/list/delete`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: formData
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
|
||||
window.location.reload();
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue