mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Remove jQuery AJAX from repo collaborator mode dropdown (#29371)
- Removed all jQuery AJAX calls and replaced with our fetch wrapper - Tested the repo collaborator mode dropdown functionality and it works as before # Demo using `fetch` instead of jQuery AJAX  --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
		| @@ -2,6 +2,7 @@ import $ from 'jquery'; | |||||||
| import {minimatch} from 'minimatch'; | import {minimatch} from 'minimatch'; | ||||||
| import {createMonaco} from './codeeditor.js'; | import {createMonaco} from './codeeditor.js'; | ||||||
| import {onInputDebounce, toggleElem} from '../utils/dom.js'; | import {onInputDebounce, toggleElem} from '../utils/dom.js'; | ||||||
|  | import {POST} from '../modules/fetch.js'; | ||||||
|  |  | ||||||
| const {appSubUrl, csrfToken} = window.config; | const {appSubUrl, csrfToken} = window.config; | ||||||
|  |  | ||||||
| @@ -11,18 +12,19 @@ export function initRepoSettingsCollaboration() { | |||||||
|     const $dropdown = $(e); |     const $dropdown = $(e); | ||||||
|     const $text = $dropdown.find('> .text'); |     const $text = $dropdown.find('> .text'); | ||||||
|     $dropdown.dropdown({ |     $dropdown.dropdown({ | ||||||
|       action(_text, value) { |       async action(_text, value) { | ||||||
|         const lastValue = $dropdown.attr('data-last-value'); |         const lastValue = $dropdown.attr('data-last-value'); | ||||||
|         $.post($dropdown.attr('data-url'), { |         try { | ||||||
|           _csrf: csrfToken, |  | ||||||
|           uid: $dropdown.attr('data-uid'), |  | ||||||
|           mode: value, |  | ||||||
|         }).fail(() => { |  | ||||||
|           $text.text('(error)'); // prevent from misleading users when error occurs |  | ||||||
|           $dropdown.attr('data-last-value', lastValue); |  | ||||||
|         }); |  | ||||||
|           $dropdown.attr('data-last-value', value); |           $dropdown.attr('data-last-value', value); | ||||||
|           $dropdown.dropdown('hide'); |           $dropdown.dropdown('hide'); | ||||||
|  |           const data = new FormData(); | ||||||
|  |           data.append('uid', $dropdown.attr('data-uid')); | ||||||
|  |           data.append('mode', value); | ||||||
|  |           await POST($dropdown.attr('data-url'), {data}); | ||||||
|  |         } catch { | ||||||
|  |           $text.text('(error)'); // prevent from misleading users when error occurs | ||||||
|  |           $dropdown.attr('data-last-value', lastValue); | ||||||
|  |         } | ||||||
|       }, |       }, | ||||||
|       onChange(_value, text, _$choice) { |       onChange(_value, text, _$choice) { | ||||||
|         $text.text(text); // update the text when using keyboard navigating |         $text.text(text); // update the text when using keyboard navigating | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user