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 all commits
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
30 changes: 16 additions & 14 deletions web_src/js/features/repo-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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', 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
}
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