mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Refactor legacy JS (#33115)
This commit is contained in:
		@@ -9,7 +9,7 @@
 | 
				
			|||||||
				{{template "org/team/navbar" .}}
 | 
									{{template "org/team/navbar" .}}
 | 
				
			||||||
				{{$canAddRemove := and $.IsOrganizationOwner (not $.Team.IncludesAllRepositories)}}
 | 
									{{$canAddRemove := and $.IsOrganizationOwner (not $.Team.IncludesAllRepositories)}}
 | 
				
			||||||
				{{if $canAddRemove}}
 | 
									{{if $canAddRemove}}
 | 
				
			||||||
					<div class="ui attached segment tw-flex tw-flex-wrap tw-gap-2">
 | 
										<div class="ui top attached segment tw-flex tw-flex-wrap tw-gap-2">
 | 
				
			||||||
						<form class="ui form ignore-dirty tw-flex-1 tw-flex" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/add" method="post">
 | 
											<form class="ui form ignore-dirty tw-flex-1 tw-flex" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/add" method="post">
 | 
				
			||||||
							{{.CsrfTokenHtml}}
 | 
												{{.CsrfTokenHtml}}
 | 
				
			||||||
							<div id="search-repo-box" data-uid="{{.Org.ID}}" class="ui search">
 | 
												<div id="search-repo-box" data-uid="{{.Org.ID}}" class="ui search">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,5 @@
 | 
				
			|||||||
import $ from 'jquery';
 | 
					 | 
				
			||||||
import {GET} from '../modules/fetch.ts';
 | 
					import {GET} from '../modules/fetch.ts';
 | 
				
			||||||
import {toggleElem, type DOMEvent} from '../utils/dom.ts';
 | 
					import {toggleElem, type DOMEvent, createElementFromHTML} from '../utils/dom.ts';
 | 
				
			||||||
import {logoutFromWorker} from '../modules/worker.ts';
 | 
					import {logoutFromWorker} from '../modules/worker.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
 | 
					const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
 | 
				
			||||||
@@ -158,7 +157,8 @@ async function updateNotificationTable() {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const data = await response.text();
 | 
					      const data = await response.text();
 | 
				
			||||||
      if ($(data).data('sequence-number') === notificationSequenceNumber) {
 | 
					      const el = createElementFromHTML(data);
 | 
				
			||||||
 | 
					      if (parseInt(el.getAttribute('data-sequence-number')) === notificationSequenceNumber) {
 | 
				
			||||||
        notificationDiv.outerHTML = data;
 | 
					        notificationDiv.outerHTML = data;
 | 
				
			||||||
        initNotificationsTable();
 | 
					        initNotificationsTable();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,35 +1,34 @@
 | 
				
			|||||||
import $ from 'jquery';
 | 
					import {queryElems, toggleElem} from '../utils/dom.ts';
 | 
				
			||||||
import {hideElem, showElem} from '../utils/dom.ts';
 | 
					import {fomanticQuery} from '../modules/fomantic/base.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const {appSubUrl} = window.config;
 | 
					const {appSubUrl} = window.config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function initOrgTeamSettings() {
 | 
					function initOrgTeamSettings() {
 | 
				
			||||||
  // Change team access mode
 | 
					  // on the page "page-content organization new team"
 | 
				
			||||||
  $('.organization.new.team input[name=permission]').on('change', () => {
 | 
					  const pageContent = document.querySelector('.page-content.organization.new.team');
 | 
				
			||||||
    const val = $('input[name=permission]:checked', '.organization.new.team').val();
 | 
					  if (!pageContent) return;
 | 
				
			||||||
    if (val === 'admin') {
 | 
					  queryElems(pageContent, 'input[name=permission]', (el) => el.addEventListener('change', () => {
 | 
				
			||||||
      hideElem('.organization.new.team .team-units');
 | 
					    // Change team access mode
 | 
				
			||||||
    } else {
 | 
					    const val = pageContent.querySelector<HTMLInputElement>('input[name=permission]:checked')?.value;
 | 
				
			||||||
      showElem('.organization.new.team .team-units');
 | 
					    toggleElem(pageContent.querySelectorAll('.team-units'), val !== 'admin');
 | 
				
			||||||
    }
 | 
					  }));
 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function initOrgTeamSearchRepoBox() {
 | 
					function initOrgTeamSearchRepoBox() {
 | 
				
			||||||
  const $searchRepoBox = $('#search-repo-box');
 | 
					  // on the page "page-content organization teams"
 | 
				
			||||||
 | 
					  const $searchRepoBox = fomanticQuery('#search-repo-box');
 | 
				
			||||||
  $searchRepoBox.search({
 | 
					  $searchRepoBox.search({
 | 
				
			||||||
    minCharacters: 2,
 | 
					    minCharacters: 2,
 | 
				
			||||||
    apiSettings: {
 | 
					    apiSettings: {
 | 
				
			||||||
      url: `${appSubUrl}/repo/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
 | 
					      url: `${appSubUrl}/repo/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
 | 
				
			||||||
      onResponse(response) {
 | 
					      onResponse(response) {
 | 
				
			||||||
        const items = [];
 | 
					        const items = [];
 | 
				
			||||||
        $.each(response.data, (_i, item) => {
 | 
					        for (const item of response.data) {
 | 
				
			||||||
          items.push({
 | 
					          items.push({
 | 
				
			||||||
            title: item.repository.full_name.split('/')[1],
 | 
					            title: item.repository.full_name.split('/')[1],
 | 
				
			||||||
            description: item.repository.full_name,
 | 
					            description: item.repository.full_name,
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        });
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return {results: items};
 | 
					        return {results: items};
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@@ -37,3 +36,9 @@ export function initOrgTeamSearchRepoBox() {
 | 
				
			|||||||
    showNoResults: false,
 | 
					    showNoResults: false,
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function initOrgTeam() {
 | 
				
			||||||
 | 
					  if (!document.querySelector('.page-content.organization')) return;
 | 
				
			||||||
 | 
					  initOrgTeamSettings();
 | 
				
			||||||
 | 
					  initOrgTeamSearchRepoBox();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,3 @@
 | 
				
			|||||||
import $ from 'jquery';
 | 
					 | 
				
			||||||
import {POST} from '../modules/fetch.ts';
 | 
					import {POST} from '../modules/fetch.ts';
 | 
				
			||||||
import {queryElems, toggleElem} from '../utils/dom.ts';
 | 
					import {queryElems, toggleElem} from '../utils/dom.ts';
 | 
				
			||||||
import {initIssueSidebarComboList} from './repo-issue-sidebar-combolist.ts';
 | 
					import {initIssueSidebarComboList} from './repo-issue-sidebar-combolist.ts';
 | 
				
			||||||
@@ -9,9 +8,8 @@ function initBranchSelector() {
 | 
				
			|||||||
  if (!elSelectBranch) return;
 | 
					  if (!elSelectBranch) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref');
 | 
					  const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref');
 | 
				
			||||||
  const $selectBranch = $(elSelectBranch);
 | 
					  const elBranchMenu = elSelectBranch.querySelector('.reference-list-menu');
 | 
				
			||||||
  const $branchMenu = $selectBranch.find('.reference-list-menu');
 | 
					  queryElems(elBranchMenu, '.item:not(.no-select)', (el) => el.addEventListener('click', async function (e) {
 | 
				
			||||||
  $branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
 | 
					 | 
				
			||||||
    e.preventDefault();
 | 
					    e.preventDefault();
 | 
				
			||||||
    const selectedValue = this.getAttribute('data-id'); // eg: "refs/heads/my-branch"
 | 
					    const selectedValue = this.getAttribute('data-id'); // eg: "refs/heads/my-branch"
 | 
				
			||||||
    const selectedText = this.getAttribute('data-name'); // eg: "my-branch"
 | 
					    const selectedText = this.getAttribute('data-name'); // eg: "my-branch"
 | 
				
			||||||
@@ -29,7 +27,7 @@ function initBranchSelector() {
 | 
				
			|||||||
      document.querySelector<HTMLInputElement>(selectedHiddenSelector).value = selectedValue;
 | 
					      document.querySelector<HTMLInputElement>(selectedHiddenSelector).value = selectedValue;
 | 
				
			||||||
      elSelectBranch.querySelector('.text-branch-name').textContent = selectedText;
 | 
					      elSelectBranch.querySelector('.text-branch-name').textContent = selectedText;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  }));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function initRepoIssueDue() {
 | 
					function initRepoIssueDue() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@ import {initUserSettings} from './features/user-settings.ts';
 | 
				
			|||||||
import {initRepoActivityTopAuthorsChart, initRepoArchiveLinks} from './features/repo-common.ts';
 | 
					import {initRepoActivityTopAuthorsChart, initRepoArchiveLinks} from './features/repo-common.ts';
 | 
				
			||||||
import {initRepoMigrationStatusChecker} from './features/repo-migrate.ts';
 | 
					import {initRepoMigrationStatusChecker} from './features/repo-migrate.ts';
 | 
				
			||||||
import {initRepoDiffView} from './features/repo-diff.ts';
 | 
					import {initRepoDiffView} from './features/repo-diff.ts';
 | 
				
			||||||
import {initOrgTeamSearchRepoBox, initOrgTeamSettings} from './features/org-team.ts';
 | 
					import {initOrgTeam} from './features/org-team.ts';
 | 
				
			||||||
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts';
 | 
					import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts';
 | 
				
			||||||
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts';
 | 
					import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts';
 | 
				
			||||||
import {initRepoEditor} from './features/repo-editor.ts';
 | 
					import {initRepoEditor} from './features/repo-editor.ts';
 | 
				
			||||||
@@ -166,8 +166,7 @@ onDomReady(() => {
 | 
				
			|||||||
    initNotificationCount,
 | 
					    initNotificationCount,
 | 
				
			||||||
    initNotificationsTable,
 | 
					    initNotificationsTable,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    initOrgTeamSearchRepoBox,
 | 
					    initOrgTeam,
 | 
				
			||||||
    initOrgTeamSettings,
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    initRepoActivityTopAuthorsChart,
 | 
					    initRepoActivityTopAuthorsChart,
 | 
				
			||||||
    initRepoArchiveLinks,
 | 
					    initRepoArchiveLinks,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user