mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 07:43:18 -05:00
Remove jQuery .attr
from the repository settings (#30018)
- Switched from jQuery `.attr` to plain javascript `getAttribute` and `setAttribute` - Tested the collaborator access mode change, team search box, and branch protection form. They all work as before --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> (cherry picked from commit 26dbca741114587f4191050a76ee1a36282a2018)
This commit is contained in:
parent
a395806812
commit
08a9a61faf
1 changed files with 16 additions and 14 deletions
|
@ -8,22 +8,22 @@ const {appSubUrl, csrfToken} = window.config;
|
|||
|
||||
export function initRepoSettingsCollaboration() {
|
||||
// Change collaborator access mode
|
||||
$('.page-content.repository .ui.dropdown.access-mode').each((_, e) => {
|
||||
const $dropdown = $(e);
|
||||
$('.page-content.repository .ui.dropdown.access-mode').each((_, el) => {
|
||||
const $dropdown = $(el);
|
||||
const $text = $dropdown.find('> .text');
|
||||
$dropdown.dropdown({
|
||||
async action(_text, value) {
|
||||
const lastValue = $dropdown.attr('data-last-value');
|
||||
const lastValue = el.getAttribute('data-last-value');
|
||||
try {
|
||||
$dropdown.attr('data-last-value', value);
|
||||
el.setAttribute('data-last-value', value);
|
||||
$dropdown.dropdown('hide');
|
||||
const data = new FormData();
|
||||
data.append('uid', $dropdown.attr('data-uid'));
|
||||
data.append('uid', el.getAttribute('data-uid'));
|
||||
data.append('mode', value);
|
||||
await POST($dropdown.attr('data-url'), {data});
|
||||
await POST(el.getAttribute('data-url'), {data});
|
||||
} catch {
|
||||
$text.text('(error)'); // prevent from misleading users when error occurs
|
||||
$dropdown.attr('data-last-value', lastValue);
|
||||
el.setAttribute('data-last-value', lastValue);
|
||||
}
|
||||
},
|
||||
onChange(_value, text, _$choice) {
|
||||
|
@ -32,9 +32,9 @@ export function initRepoSettingsCollaboration() {
|
|||
onHide() {
|
||||
// set to the really selected value, defer to next tick to make sure `action` has finished its work because the calling order might be onHide -> action
|
||||
setTimeout(() => {
|
||||
const $item = $dropdown.dropdown('get item', $dropdown.attr('data-last-value'));
|
||||
const $item = $dropdown.dropdown('get item', el.getAttribute('data-last-value'));
|
||||
if ($item) {
|
||||
$dropdown.dropdown('set selected', $dropdown.attr('data-last-value'));
|
||||
$dropdown.dropdown('set selected', el.getAttribute('data-last-value'));
|
||||
} else {
|
||||
$text.text('(none)'); // prevent from misleading users when the access mode is undefined
|
||||
}
|
||||
|
@ -45,11 +45,13 @@ export function initRepoSettingsCollaboration() {
|
|||
}
|
||||
|
||||
export function initRepoSettingSearchTeamBox() {
|
||||
const $searchTeamBox = $('#search-team-box');
|
||||
$searchTeamBox.search({
|
||||
const searchTeamBox = document.getElementById('search-team-box');
|
||||
if (!searchTeamBox) return;
|
||||
|
||||
$(searchTeamBox).search({
|
||||
minCharacters: 2,
|
||||
apiSettings: {
|
||||
url: `${appSubUrl}/org/${$searchTeamBox.attr('data-org-name')}/teams/-/search?q={query}`,
|
||||
url: `${appSubUrl}/org/${searchTeamBox.getAttribute('data-org-name')}/teams/-/search?q={query}`,
|
||||
headers: {'X-Csrf-Token': csrfToken},
|
||||
onResponse(response) {
|
||||
const items = [];
|
||||
|
@ -77,11 +79,11 @@ export function initRepoSettingGitHook() {
|
|||
export function initRepoSettingBranches() {
|
||||
if (!$('.repository.settings.branches').length) return;
|
||||
$('.toggle-target-enabled').on('change', function () {
|
||||
const $target = $($(this).attr('data-target'));
|
||||
const $target = $(this.getAttribute('data-target'));
|
||||
$target.toggleClass('disabled', !this.checked);
|
||||
});
|
||||
$('.toggle-target-disabled').on('change', function () {
|
||||
const $target = $($(this).attr('data-target'));
|
||||
const $target = $(this.getAttribute('data-target'));
|
||||
if (this.checked) $target.addClass('disabled'); // only disable, do not auto enable
|
||||
});
|
||||
$('#dismiss_stale_approvals').on('change', function () {
|
||||
|
|
Loading…
Reference in a new issue