mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	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  Signed-off-by: Yarden Shoham <git@yardenshoham.com>
This commit is contained in:
		| @@ -11,7 +11,7 @@ import {htmlEscape} from 'escape-goat'; | |||||||
| import {showTemporaryTooltip} from '../modules/tippy.js'; | import {showTemporaryTooltip} from '../modules/tippy.js'; | ||||||
| import {confirmModal} from './comp/ConfirmModal.js'; | import {confirmModal} from './comp/ConfirmModal.js'; | ||||||
| import {showErrorToast} from '../modules/toast.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'; | import '../htmx.js'; | ||||||
|  |  | ||||||
| const {appUrl, appSubUrl, csrfToken, i18n} = window.config; | const {appUrl, appSubUrl, csrfToken, i18n} = window.config; | ||||||
| @@ -37,11 +37,10 @@ export function initHeadNavbarContentToggle() { | |||||||
| } | } | ||||||
|  |  | ||||||
| export function initFootLanguageMenu() { | export function initFootLanguageMenu() { | ||||||
|   function linkLanguageAction() { |   async function linkLanguageAction() { | ||||||
|     const $this = $(this); |     const $this = $(this); | ||||||
|     $.get($this.data('url')).always(() => { |     await GET($this.data('url')); | ||||||
|       window.location.reload(); |     window.location.reload(); | ||||||
|     }); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   $('.language-menu a[lang]').on('click', linkLanguageAction); |   $('.language-menu a[lang]').on('click', linkLanguageAction); | ||||||
| @@ -309,27 +308,26 @@ export function initGlobalLinkActions() { | |||||||
|  |  | ||||||
|     dialog.modal({ |     dialog.modal({ | ||||||
|       closable: false, |       closable: false, | ||||||
|       onApprove() { |       onApprove: async () => { | ||||||
|         if ($this.data('type') === 'form') { |         if ($this.data('type') === 'form') { | ||||||
|           $($this.data('form')).trigger('submit'); |           $($this.data('form')).trigger('submit'); | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
|  |         const postData = new FormData(); | ||||||
|         const postData = { |  | ||||||
|           _csrf: csrfToken, |  | ||||||
|         }; |  | ||||||
|         for (const [key, value] of Object.entries(dataArray)) { |         for (const [key, value] of Object.entries(dataArray)) { | ||||||
|           if (key && key.startsWith('data')) { |           if (key && key.startsWith('data')) { | ||||||
|             postData[key.slice(4)] = value; |             postData.append(key.slice(4), value); | ||||||
|           } |           } | ||||||
|           if (key === 'id') { |           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; |           window.location.href = data.redirect; | ||||||
|         }); |         } | ||||||
|       } |       } | ||||||
|     }).modal('show'); |     }).modal('show'); | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Yarden Shoham
					Yarden Shoham