Skip to content

Commit ef736b7

Browse files
authored
Refactor legacy JS (#33115)
1 parent 40765b5 commit ef736b7

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

templates/org/team/repositories.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{{template "org/team/navbar" .}}
1010
{{$canAddRemove := and $.IsOrganizationOwner (not $.Team.IncludesAllRepositories)}}
1111
{{if $canAddRemove}}
12-
<div class="ui attached segment tw-flex tw-flex-wrap tw-gap-2">
12+
<div class="ui top attached segment tw-flex tw-flex-wrap tw-gap-2">
1313
<form class="ui form ignore-dirty tw-flex-1 tw-flex" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/add" method="post">
1414
{{.CsrfTokenHtml}}
1515
<div id="search-repo-box" data-uid="{{.Org.ID}}" class="ui search">

web_src/js/features/notification.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import $ from 'jquery';
21
import {GET} from '../modules/fetch.ts';
3-
import {toggleElem, type DOMEvent} from '../utils/dom.ts';
2+
import {toggleElem, type DOMEvent, createElementFromHTML} from '../utils/dom.ts';
43
import {logoutFromWorker} from '../modules/worker.ts';
54

65
const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
@@ -158,7 +157,8 @@ async function updateNotificationTable() {
158157
}
159158

160159
const data = await response.text();
161-
if ($(data).data('sequence-number') === notificationSequenceNumber) {
160+
const el = createElementFromHTML(data);
161+
if (parseInt(el.getAttribute('data-sequence-number')) === notificationSequenceNumber) {
162162
notificationDiv.outerHTML = data;
163163
initNotificationsTable();
164164
}

web_src/js/features/org-team.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
import $ from 'jquery';
2-
import {hideElem, showElem} from '../utils/dom.ts';
1+
import {queryElems, toggleElem} from '../utils/dom.ts';
2+
import {fomanticQuery} from '../modules/fomantic/base.ts';
33

44
const {appSubUrl} = window.config;
55

6-
export function initOrgTeamSettings() {
7-
// Change team access mode
8-
$('.organization.new.team input[name=permission]').on('change', () => {
9-
const val = $('input[name=permission]:checked', '.organization.new.team').val();
10-
if (val === 'admin') {
11-
hideElem('.organization.new.team .team-units');
12-
} else {
13-
showElem('.organization.new.team .team-units');
14-
}
15-
});
6+
function initOrgTeamSettings() {
7+
// on the page "page-content organization new team"
8+
const pageContent = document.querySelector('.page-content.organization.new.team');
9+
if (!pageContent) return;
10+
queryElems(pageContent, 'input[name=permission]', (el) => el.addEventListener('change', () => {
11+
// Change team access mode
12+
const val = pageContent.querySelector<HTMLInputElement>('input[name=permission]:checked')?.value;
13+
toggleElem(pageContent.querySelectorAll('.team-units'), val !== 'admin');
14+
}));
1615
}
1716

18-
export function initOrgTeamSearchRepoBox() {
19-
const $searchRepoBox = $('#search-repo-box');
17+
function initOrgTeamSearchRepoBox() {
18+
// on the page "page-content organization teams"
19+
const $searchRepoBox = fomanticQuery('#search-repo-box');
2020
$searchRepoBox.search({
2121
minCharacters: 2,
2222
apiSettings: {
2323
url: `${appSubUrl}/repo/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
2424
onResponse(response) {
2525
const items = [];
26-
$.each(response.data, (_i, item) => {
26+
for (const item of response.data) {
2727
items.push({
2828
title: item.repository.full_name.split('/')[1],
2929
description: item.repository.full_name,
3030
});
31-
});
32-
31+
}
3332
return {results: items};
3433
},
3534
},
3635
searchFields: ['full_name'],
3736
showNoResults: false,
3837
});
3938
}
39+
40+
export function initOrgTeam() {
41+
if (!document.querySelector('.page-content.organization')) return;
42+
initOrgTeamSettings();
43+
initOrgTeamSearchRepoBox();
44+
}

web_src/js/features/repo-issue-sidebar.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import $ from 'jquery';
21
import {POST} from '../modules/fetch.ts';
32
import {queryElems, toggleElem} from '../utils/dom.ts';
43
import {initIssueSidebarComboList} from './repo-issue-sidebar-combolist.ts';
@@ -9,9 +8,8 @@ function initBranchSelector() {
98
if (!elSelectBranch) return;
109

1110
const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref');
12-
const $selectBranch = $(elSelectBranch);
13-
const $branchMenu = $selectBranch.find('.reference-list-menu');
14-
$branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
11+
const elBranchMenu = elSelectBranch.querySelector('.reference-list-menu');
12+
queryElems(elBranchMenu, '.item:not(.no-select)', (el) => el.addEventListener('click', async function (e) {
1513
e.preventDefault();
1614
const selectedValue = this.getAttribute('data-id'); // eg: "refs/heads/my-branch"
1715
const selectedText = this.getAttribute('data-name'); // eg: "my-branch"
@@ -29,7 +27,7 @@ function initBranchSelector() {
2927
document.querySelector<HTMLInputElement>(selectedHiddenSelector).value = selectedValue;
3028
elSelectBranch.querySelector('.text-branch-name').textContent = selectedText;
3129
}
32-
});
30+
}));
3331
}
3432

3533
function initRepoIssueDue() {

web_src/js/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {initUserSettings} from './features/user-settings.ts';
4040
import {initRepoActivityTopAuthorsChart, initRepoArchiveLinks} from './features/repo-common.ts';
4141
import {initRepoMigrationStatusChecker} from './features/repo-migrate.ts';
4242
import {initRepoDiffView} from './features/repo-diff.ts';
43-
import {initOrgTeamSearchRepoBox, initOrgTeamSettings} from './features/org-team.ts';
43+
import {initOrgTeam} from './features/org-team.ts';
4444
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts';
4545
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts';
4646
import {initRepoEditor} from './features/repo-editor.ts';
@@ -166,8 +166,7 @@ onDomReady(() => {
166166
initNotificationCount,
167167
initNotificationsTable,
168168

169-
initOrgTeamSearchRepoBox,
170-
initOrgTeamSettings,
169+
initOrgTeam,
171170

172171
initRepoActivityTopAuthorsChart,
173172
initRepoArchiveLinks,

0 commit comments

Comments
 (0)