summaryrefslogtreecommitdiffstats
path: root/web_src/js/features
diff options
context:
space:
mode:
authorYarden Shoham <git@yardenshoham.com>2024-03-02 10:48:14 +0200
committerGitHub <noreply@github.com>2024-03-02 16:48:14 +0800
commit8a0a83a1b53f55bcc710c3b229cba1c1bcf471c6 (patch)
tree16a523fe152be5c33806d447c742df7d64050c8a /web_src/js/features
parent9de5e39e25009bacc5ca201ed97e9cbb623e56e9 (diff)
downloadgitea-8a0a83a1b53f55bcc710c3b229cba1c1bcf471c6.tar.gz
gitea-8a0a83a1b53f55bcc710c3b229cba1c1bcf471c6.zip
Remove jQuery AJAX from common global functions (#29528)
- Removed all jQuery AJAX calls and replaced with our fetch wrapper - Tested the locale change functionality and it works as before - Tested the delete button functionality and it works as before # Demo using `fetch` instead of jQuery AJAX ![action](https://github.com/go-gitea/gitea/assets/20454870/8a024f75-c2a5-4bff-898d-ca751d2489f1) Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Diffstat (limited to 'web_src/js/features')
-rw-r--r--web_src/js/features/common-global.js26
1 files changed, 12 insertions, 14 deletions
diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js
index cd0fc6d6a9..f90591aff3 100644
--- a/web_src/js/features/common-global.js
+++ b/web_src/js/features/common-global.js
@@ -11,7 +11,7 @@ import {htmlEscape} from 'escape-goat';
import {showTemporaryTooltip} from '../modules/tippy.js';
import {confirmModal} from './comp/ConfirmModal.js';
import {showErrorToast} from '../modules/toast.js';
-import {request, POST} from '../modules/fetch.js';
+import {request, POST, GET} from '../modules/fetch.js';
import '../htmx.js';
const {appUrl, appSubUrl, csrfToken, i18n} = window.config;
@@ -37,11 +37,10 @@ export function initHeadNavbarContentToggle() {
}
export function initFootLanguageMenu() {
- function linkLanguageAction() {
+ async function linkLanguageAction() {
const $this = $(this);
- $.get($this.data('url')).always(() => {
- window.location.reload();
- });
+ await GET($this.data('url'));
+ window.location.reload();
}
$('.language-menu a[lang]').on('click', linkLanguageAction);
@@ -309,27 +308,26 @@ export function initGlobalLinkActions() {
dialog.modal({
closable: false,
- onApprove() {
+ onApprove: async () => {
if ($this.data('type') === 'form') {
$($this.data('form')).trigger('submit');
return;
}
-
- const postData = {
- _csrf: csrfToken,
- };
+ const postData = new FormData();
for (const [key, value] of Object.entries(dataArray)) {
if (key && key.startsWith('data')) {
- postData[key.slice(4)] = value;
+ postData.append(key.slice(4), value);
}
if (key === 'id') {
- postData['id'] = value;
+ postData.append('id', value);
}
}
- $.post($this.data('url'), postData).done((data) => {
+ const response = await POST($this.data('url'), {data: postData});
+ if (response.ok) {
+ const data = await response.json();
window.location.href = data.redirect;
- });
+ }
}
}).modal('show');
}