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

![action](https://github.com/go-gitea/gitea/assets/20454870/04466629-19b2-4469-9231-38820ee13c36)

---------

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Giteabot <teabot@gitea.io>
(cherry picked from commit 15d071f4f81a0ad09f260de83cb6402875b4de27)
This commit is contained in:
Yarden Shoham 2024-02-25 01:08:51 +02:00 committed by Earl Warren
parent f92c3de965
commit 5362ce7a42
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 0579CB2928A78A00

View file

@ -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, $dropdown.attr('data-last-value', value);
uid: $dropdown.attr('data-uid'), $dropdown.dropdown('hide');
mode: value, const data = new FormData();
}).fail(() => { 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 $text.text('(error)'); // prevent from misleading users when error occurs
$dropdown.attr('data-last-value', lastValue); $dropdown.attr('data-last-value', lastValue);
}); }
$dropdown.attr('data-last-value', value);
$dropdown.dropdown('hide');
}, },
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