Skip to content

Commit 15d071f

Browse files
yardenshohamdelvhGiteaBot
authored
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 <[email protected]> Co-authored-by: delvh <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent 10c7996 commit 15d071f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

web_src/js/features/repo-settings.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import $ from 'jquery';
22
import {minimatch} from 'minimatch';
33
import {createMonaco} from './codeeditor.js';
44
import {onInputDebounce, toggleElem} from '../utils/dom.js';
5+
import {POST} from '../modules/fetch.js';
56

67
const {appSubUrl, csrfToken} = window.config;
78

@@ -11,18 +12,19 @@ export function initRepoSettingsCollaboration() {
1112
const $dropdown = $(e);
1213
const $text = $dropdown.find('> .text');
1314
$dropdown.dropdown({
14-
action(_text, value) {
15+
async action(_text, value) {
1516
const lastValue = $dropdown.attr('data-last-value');
16-
$.post($dropdown.attr('data-url'), {
17-
_csrf: csrfToken,
18-
uid: $dropdown.attr('data-uid'),
19-
mode: value,
20-
}).fail(() => {
17+
try {
18+
$dropdown.attr('data-last-value', value);
19+
$dropdown.dropdown('hide');
20+
const data = new FormData();
21+
data.append('uid', $dropdown.attr('data-uid'));
22+
data.append('mode', value);
23+
await POST($dropdown.attr('data-url'), {data});
24+
} catch {
2125
$text.text('(error)'); // prevent from misleading users when error occurs
2226
$dropdown.attr('data-last-value', lastValue);
23-
});
24-
$dropdown.attr('data-last-value', value);
25-
$dropdown.dropdown('hide');
27+
}
2628
},
2729
onChange(_value, text, _$choice) {
2830
$text.text(text); // update the text when using keyboard navigating

0 commit comments

Comments
 (0)