feat(initGlobalDeleteButton): add option http method delete when data-method is delete

pull/33138/head
zsbahtiar 1 month ago
parent c8dbc29c9a
commit 3938aeadd5
  1. 7
      web_src/js/features/common-button.ts

@ -1,4 +1,4 @@
import {POST} from '../modules/fetch.ts';
import {DELETE, POST} from '../modules/fetch.ts';
import {addDelegatedEventListener, hideElem, queryElems, showElem, toggleElem} from '../utils/dom.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts';
import {camelize} from 'vue';
@ -62,7 +62,10 @@ export function initGlobalDeleteButton(): void {
}
}
const response = await POST(btn.getAttribute('data-url'), {data: postData});
const method = btn.getAttribute('data-method')?.toUpperCase() || 'POST';
const response = method === 'DELETE'
? await DELETE(btn.getAttribute('data-url'))
: await POST(btn.getAttribute('data-url'), {data: postData});
if (response.ok) {
const data = await response.json();
window.location.href = data.redirect;

Loading…
Cancel
Save