mirror of
https://github.com/go-gitea/gitea
synced 2024-11-19 00:24:31 +00:00
Backport #30881 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
2f91a461f7
commit
5f1af1f37d
@ -1,12 +1,8 @@
|
|||||||
{{if and (not .Issue.IsPull) (not .PageIsComparePull)}}
|
{{if and (not .Issue.IsPull) (not .PageIsComparePull)}}
|
||||||
<input id="ref_selector" name="ref" type="hidden" value="{{.Reference}}">
|
<input id="ref_selector" name="ref" type="hidden" value="{{.Reference}}">
|
||||||
<input id="editing_mode" name="edit_mode" type="hidden" value="{{(or .IsIssueWriter .HasIssuesOrPullsWritePermission)}}">
|
|
||||||
<form method="post" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref" id="update_issueref_form">
|
|
||||||
{{$.CsrfTokenHtml}}
|
|
||||||
</form>
|
|
||||||
<div class="ui dropdown select-branch branch-selector-dropdown ellipsis-items-nowrap {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}}"
|
<div class="ui dropdown select-branch branch-selector-dropdown ellipsis-items-nowrap {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}}"
|
||||||
data-no-results="{{ctx.Locale.Tr "no_results_found"}}"
|
data-no-results="{{ctx.Locale.Tr "no_results_found"}}"
|
||||||
{{if not .Issue}}data-for-new-issue="true"{{end}}
|
{{if and .Issue (or .IsIssueWriter .HasIssuesOrPullsWritePermission)}}data-url-update-issueref="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref"{{end}}
|
||||||
>
|
>
|
||||||
<div class="ui button branch-dropdown-button">
|
<div class="ui button branch-dropdown-button">
|
||||||
<span class="text-branch-name gt-ellipsis">{{if .Reference}}{{$.RefEndName}}{{else}}{{ctx.Locale.Tr "repo.issues.no_ref"}}{{end}}</span>
|
<span class="text-branch-name gt-ellipsis">{{if .Reference}}{{$.RefEndName}}{{else}}{{ctx.Locale.Tr "repo.issues.no_ref"}}{{end}}</span>
|
||||||
|
@ -58,32 +58,27 @@ export function initRepoCommentForm() {
|
|||||||
function initBranchSelector() {
|
function initBranchSelector() {
|
||||||
const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
|
const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
|
||||||
if (!elSelectBranch) return;
|
if (!elSelectBranch) return;
|
||||||
const isForNewIssue = elSelectBranch.getAttribute('data-for-new-issue') === 'true';
|
|
||||||
|
|
||||||
|
const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref');
|
||||||
const $selectBranch = $(elSelectBranch);
|
const $selectBranch = $(elSelectBranch);
|
||||||
const $branchMenu = $selectBranch.find('.reference-list-menu');
|
const $branchMenu = $selectBranch.find('.reference-list-menu');
|
||||||
$branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
|
$branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const selectedValue = $(this).data('id'); // eg: "refs/heads/my-branch"
|
const selectedValue = this.getAttribute('data-id'); // eg: "refs/heads/my-branch"
|
||||||
const editMode = $('#editing_mode').val();
|
const selectedText = this.getAttribute('data-name'); // eg: "my-branch"
|
||||||
$($(this).data('id-selector')).val(selectedValue);
|
if (urlUpdateIssueRef) {
|
||||||
if (isForNewIssue) {
|
// for existing issue, send request to update issue ref, and reload page
|
||||||
elSelectBranch.querySelector('.text-branch-name').textContent = this.getAttribute('data-name');
|
|
||||||
return; // only update UI&form, do not send request/reload
|
|
||||||
}
|
|
||||||
|
|
||||||
if (editMode === 'true') {
|
|
||||||
const form = document.getElementById('update_issueref_form');
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append('ref', selectedValue);
|
|
||||||
try {
|
try {
|
||||||
await POST(form.getAttribute('action'), {data: params});
|
await POST(urlUpdateIssueRef, {data: new URLSearchParams({ref: selectedValue})});
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
} else if (editMode === '') {
|
} else {
|
||||||
$selectBranch.find('.ui .branch-name').text(selectedValue);
|
// for new issue, only update UI&form, do not send request/reload
|
||||||
|
const selectedHiddenSelector = this.getAttribute('data-id-selector');
|
||||||
|
document.querySelector(selectedHiddenSelector).value = selectedValue;
|
||||||
|
elSelectBranch.querySelector('.text-branch-name').textContent = selectedText;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$selectBranch.find('.reference.column').on('click', function () {
|
$selectBranch.find('.reference.column').on('click', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user