mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	| @@ -1,10 +1,10 @@ | |||||||
| import $ from 'jquery'; |  | ||||||
| import {minimatch} from 'minimatch'; | import {minimatch} from 'minimatch'; | ||||||
| import {createMonaco} from './codeeditor.ts'; | import {createMonaco} from './codeeditor.ts'; | ||||||
| import {onInputDebounce, queryElems, toggleElem} from '../utils/dom.ts'; | import {onInputDebounce, queryElems, toggleElem} from '../utils/dom.ts'; | ||||||
| import {POST} from '../modules/fetch.ts'; | import {POST} from '../modules/fetch.ts'; | ||||||
| import {initAvatarUploaderWithCropper} from './comp/Cropper.ts'; | import {initAvatarUploaderWithCropper} from './comp/Cropper.ts'; | ||||||
| import {initRepoSettingsBranchesDrag} from './repo-settings-branches.ts'; | import {initRepoSettingsBranchesDrag} from './repo-settings-branches.ts'; | ||||||
|  | import {fomanticQuery} from '../modules/fomantic/base.ts'; | ||||||
|  |  | ||||||
| const {appSubUrl, csrfToken} = window.config; | const {appSubUrl, csrfToken} = window.config; | ||||||
|  |  | ||||||
| @@ -12,11 +12,12 @@ function initRepoSettingsCollaboration() { | |||||||
|   // Change collaborator access mode |   // Change collaborator access mode | ||||||
|   for (const dropdownEl of queryElems(document, '.page-content.repository .ui.dropdown.access-mode')) { |   for (const dropdownEl of queryElems(document, '.page-content.repository .ui.dropdown.access-mode')) { | ||||||
|     const textEl = dropdownEl.querySelector(':scope > .text'); |     const textEl = dropdownEl.querySelector(':scope > .text'); | ||||||
|     $(dropdownEl).dropdown({ |     const $dropdown = fomanticQuery(dropdownEl); | ||||||
|  |     $dropdown.dropdown({ | ||||||
|       async action(text: string, value: string) { |       async action(text: string, value: string) { | ||||||
|         dropdownEl.classList.add('is-loading', 'loading-icon-2px'); |         dropdownEl.classList.add('is-loading', 'loading-icon-2px'); | ||||||
|         const lastValue = dropdownEl.getAttribute('data-last-value'); |         const lastValue = dropdownEl.getAttribute('data-last-value'); | ||||||
|         $(dropdownEl).dropdown('hide'); |         $dropdown.dropdown('hide'); | ||||||
|         try { |         try { | ||||||
|           const uid = dropdownEl.getAttribute('data-uid'); |           const uid = dropdownEl.getAttribute('data-uid'); | ||||||
|           await POST(dropdownEl.getAttribute('data-url'), {data: new URLSearchParams({uid, 'mode': value})}); |           await POST(dropdownEl.getAttribute('data-url'), {data: new URLSearchParams({uid, 'mode': value})}); | ||||||
| @@ -33,9 +34,9 @@ function initRepoSettingsCollaboration() { | |||||||
|         // set to the really selected value, defer to next tick to make sure `action` has finished |         // 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 |         // its work because the calling order might be onHide -> action | ||||||
|         setTimeout(() => { |         setTimeout(() => { | ||||||
|           const $item = $(dropdownEl).dropdown('get item', dropdownEl.getAttribute('data-last-value')); |           const $item = $dropdown.dropdown('get item', dropdownEl.getAttribute('data-last-value')); | ||||||
|           if ($item) { |           if ($item) { | ||||||
|             $(dropdownEl).dropdown('set selected', dropdownEl.getAttribute('data-last-value')); |             $dropdown.dropdown('set selected', dropdownEl.getAttribute('data-last-value')); | ||||||
|           } else { |           } else { | ||||||
|             textEl.textContent = '(none)'; // prevent from misleading users when the access mode is undefined |             textEl.textContent = '(none)'; // prevent from misleading users when the access mode is undefined | ||||||
|           } |           } | ||||||
| @@ -49,32 +50,32 @@ function initRepoSettingsSearchTeamBox() { | |||||||
|   const searchTeamBox = document.querySelector('#search-team-box'); |   const searchTeamBox = document.querySelector('#search-team-box'); | ||||||
|   if (!searchTeamBox) return; |   if (!searchTeamBox) return; | ||||||
|  |  | ||||||
|   $(searchTeamBox).search({ |   fomanticQuery(searchTeamBox).search({ | ||||||
|     minCharacters: 2, |     minCharacters: 2, | ||||||
|  |     searchFields: ['name', 'description'], | ||||||
|  |     showNoResults: false, | ||||||
|  |     rawResponse: true, | ||||||
|     apiSettings: { |     apiSettings: { | ||||||
|       url: `${appSubUrl}/org/${searchTeamBox.getAttribute('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: any) { |       onResponse(response: any) { | ||||||
|         const items: Array<Record<string, any>> = []; |         const items: Array<Record<string, any>> = []; | ||||||
|         $.each(response.data, (_i, item) => { |         for (const item of response.data) { | ||||||
|           items.push({ |           items.push({ | ||||||
|             title: item.name, |             title: item.name, | ||||||
|             description: `${item.permission} access`, // TODO: translate this string |             description: `${item.permission} access`, // TODO: translate this string | ||||||
|           }); |           }); | ||||||
|         }); |         } | ||||||
|  |  | ||||||
|         return {results: items}; |         return {results: items}; | ||||||
|       }, |       }, | ||||||
|     }, |     }, | ||||||
|     searchFields: ['name', 'description'], |  | ||||||
|     showNoResults: false, |  | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function initRepoSettingsGitHook() { | function initRepoSettingsGitHook() { | ||||||
|   if (!$('.edit.githook').length) return; |   if (!document.querySelector('.page-content.repository.settings.edit.githook')) return; | ||||||
|   const filename = document.querySelector('.hook-filename').textContent; |   const filename = document.querySelector('.hook-filename').textContent; | ||||||
|   createMonaco($('#content')[0] as HTMLTextAreaElement, filename, {language: 'shell'}); |   createMonaco(document.querySelector<HTMLTextAreaElement>('#content'), filename, {language: 'shell'}); | ||||||
| } | } | ||||||
|  |  | ||||||
| function initRepoSettingsBranches() { | function initRepoSettingsBranches() { | ||||||
| @@ -121,32 +122,31 @@ function initRepoSettingsBranches() { | |||||||
| } | } | ||||||
|  |  | ||||||
| function initRepoSettingsOptions() { | function initRepoSettingsOptions() { | ||||||
|   if ($('.repository.settings.options').length > 0) { |   const pageContent = document.querySelector('.page-content.repository.settings.options'); | ||||||
|  |   if (!pageContent) return; | ||||||
|  |  | ||||||
|  |   const toggleClass = (elems: NodeListOf<Element>, className: string, value: boolean) => { | ||||||
|  |     for (const el of elems) el.classList.toggle(className, value); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|   // Enable or select internal/external wiki system and issue tracker. |   // Enable or select internal/external wiki system and issue tracker. | ||||||
|     $('.enable-system').on('change', function (this: HTMLInputElement) { // eslint-disable-line @typescript-eslint/no-deprecated |   queryElems<HTMLInputElement>(pageContent, '.enable-system', (el) => el.addEventListener('change', () => { | ||||||
|       if (this.checked) { |     const elTargets = document.querySelectorAll(el.getAttribute('data-target')); | ||||||
|         $($(this).data('target')).removeClass('disabled'); |     const elContexts = document.querySelectorAll(el.getAttribute('data-context')); | ||||||
|         if (!$(this).data('context')) $($(this).data('context')).addClass('disabled'); |     toggleClass(elTargets, 'disabled', !el.checked); | ||||||
|       } else { |     toggleClass(elContexts, 'disabled', el.checked); | ||||||
|         $($(this).data('target')).addClass('disabled'); |   })); | ||||||
|         if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled'); |   queryElems<HTMLInputElement>(pageContent, '.enable-system-radio', (el) => el.addEventListener('change', () => { | ||||||
|       } |     const elTargets = document.querySelectorAll(el.getAttribute('data-target')); | ||||||
|     }); |     const elContexts = document.querySelectorAll(el.getAttribute('data-context')); | ||||||
|     $('.enable-system-radio').on('change', function (this: HTMLInputElement) { // eslint-disable-line @typescript-eslint/no-deprecated |     toggleClass(elTargets, 'disabled', el.value === 'false'); | ||||||
|       if (this.value === 'false') { |     toggleClass(elContexts, 'disabled', el.value === 'true'); | ||||||
|         $($(this).data('target')).addClass('disabled'); |   })); | ||||||
|         if ($(this).data('context') !== undefined) $($(this).data('context')).removeClass('disabled'); |  | ||||||
|       } else if (this.value === 'true') { |   queryElems<HTMLInputElement>(pageContent, '.js-tracker-issue-style', (el) => el.addEventListener('change', () => { | ||||||
|         $($(this).data('target')).removeClass('disabled'); |     const checkedVal = el.value; | ||||||
|         if ($(this).data('context') !== undefined) $($(this).data('context')).addClass('disabled'); |     pageContent.querySelector('#tracker-issue-style-regex-box').classList.toggle('disabled', checkedVal !== 'regexp'); | ||||||
|       } |   })); | ||||||
|     }); |  | ||||||
|     const $trackerIssueStyleRadios = $('.js-tracker-issue-style'); |  | ||||||
|     $trackerIssueStyleRadios.on('change input', () => { |  | ||||||
|       const checkedVal = $trackerIssueStyleRadios.filter(':checked').val(); |  | ||||||
|       $('#tracker-issue-style-regex-box').toggleClass('disabled', checkedVal !== 'regexp'); |  | ||||||
|     }); |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| export function initRepoSettings() { | export function initRepoSettings() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 wxiaoguang
					wxiaoguang