Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove jQuery .attr from the repository settings #30018

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions web_src/js/features/repo-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export function initRepoSettingsCollaboration() {
const $text = $dropdown.find('> .text');
$dropdown.dropdown({
async action(_text, value) {
const lastValue = $dropdown.attr('data-last-value');
const lastValue = e.getAttribute('data-last-value');
silverwind marked this conversation as resolved.
Show resolved Hide resolved
try {
$dropdown.attr('data-last-value', value);
e.setAttribute('data-last-value', value);
$dropdown.dropdown('hide');
const data = new FormData();
data.append('uid', $dropdown.attr('data-uid'));
data.append('uid', e.getAttribute('data-uid'));
data.append('mode', value);
await POST($dropdown.attr('data-url'), {data});
await POST(e.getAttribute('data-url'), {data});
} catch {
$text.text('(error)'); // prevent from misleading users when error occurs
$dropdown.attr('data-last-value', lastValue);
e.setAttribute('data-last-value', lastValue);
}
},
onChange(_value, text, _$choice) {
Expand All @@ -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', e.getAttribute('data-last-value'));
if ($item) {
$dropdown.dropdown('set selected', $dropdown.attr('data-last-value'));
$dropdown.dropdown('set selected', e.getAttribute('data-last-value'));
} else {
$text.text('(none)'); // prevent from misleading users when the access mode is undefined
}
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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 () {
Expand Down