mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-26 07:15:43 +03: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() {
|
export function initRepoSettingsCollaboration() {
|
||||||
// Change collaborator access mode
|
// Change collaborator access mode
|
||||||
$('.page-content.repository .ui.dropdown.access-mode').each((_, e) => {
|
$('.page-content.repository .ui.dropdown.access-mode').each((_, el) => {
|
||||||
const $dropdown = $(e);
|
const $dropdown = $(el);
|
||||||
const $text = $dropdown.find('> .text');
|
const $text = $dropdown.find('> .text');
|
||||||
$dropdown.dropdown({
|
$dropdown.dropdown({
|
||||||
async action(_text, value) {
|
async action(_text, value) {
|
||||||
const lastValue = $dropdown.attr('data-last-value');
|
const lastValue = el.getAttribute('data-last-value');
|
||||||
try {
|
try {
|
||||||
$dropdown.attr('data-last-value', value);
|
el.setAttribute('data-last-value', value);
|
||||||
$dropdown.dropdown('hide');
|
$dropdown.dropdown('hide');
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
data.append('uid', $dropdown.attr('data-uid'));
|
data.append('uid', el.getAttribute('data-uid'));
|
||||||
data.append('mode', value);
|
data.append('mode', value);
|
||||||
await POST($dropdown.attr('data-url'), {data});
|
await POST(el.getAttribute('data-url'), {data});
|
||||||
} catch {
|
} 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);
|
el.setAttribute('data-last-value', lastValue);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onChange(_value, text, _$choice) {
|
onChange(_value, text, _$choice) {
|
||||||
|
@ -32,9 +32,9 @@ export function initRepoSettingsCollaboration() {
|
||||||
onHide() {
|
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
|
// 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(() => {
|
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) {
|
if ($item) {
|
||||||
$dropdown.dropdown('set selected', $dropdown.attr('data-last-value'));
|
$dropdown.dropdown('set selected', el.getAttribute('data-last-value'));
|
||||||
} else {
|
} else {
|
||||||
$text.text('(none)'); // prevent from misleading users when the access mode is undefined
|
$text.text('(none)'); // prevent from misleading users when the access mode is undefined
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,13 @@ export function initRepoSettingsCollaboration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initRepoSettingSearchTeamBox() {
|
export function initRepoSettingSearchTeamBox() {
|
||||||
const $searchTeamBox = $('#search-team-box');
|
const searchTeamBox = document.getElementById('search-team-box');
|
||||||
$searchTeamBox.search({
|
if (!searchTeamBox) return;
|
||||||
|
|
||||||
|
$(searchTeamBox).search({
|
||||||
minCharacters: 2,
|
minCharacters: 2,
|
||||||
apiSettings: {
|
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},
|
headers: {'X-Csrf-Token': csrfToken},
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
const items = [];
|
const items = [];
|
||||||
|
@ -77,11 +79,11 @@ export function initRepoSettingGitHook() {
|
||||||
export function initRepoSettingBranches() {
|
export function initRepoSettingBranches() {
|
||||||
if (!$('.repository.settings.branches').length) return;
|
if (!$('.repository.settings.branches').length) return;
|
||||||
$('.toggle-target-enabled').on('change', function () {
|
$('.toggle-target-enabled').on('change', function () {
|
||||||
const $target = $($(this).attr('data-target'));
|
const $target = $(this.getAttribute('data-target'));
|
||||||
$target.toggleClass('disabled', !this.checked);
|
$target.toggleClass('disabled', !this.checked);
|
||||||
});
|
});
|
||||||
$('.toggle-target-disabled').on('change', function () {
|
$('.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
|
if (this.checked) $target.addClass('disabled'); // only disable, do not auto enable
|
||||||
});
|
});
|
||||||
$('#dismiss_stale_approvals').on('change', function () {
|
$('#dismiss_stale_approvals').on('change', function () {
|
||||||
|
|
Loading…
Reference in a new issue