Merge pull request 'Implement external release assets' (#1445) from maltejur/forgejo:forgejo-external-attachments into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1445
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-07-30 15:50:57 +00:00
commit 94933470cd
22 changed files with 826 additions and 119 deletions

View file

@ -6,7 +6,8 @@ export function initRepoRelease() {
el.addEventListener('click', (e) => {
const uuid = e.target.getAttribute('data-uuid');
const id = e.target.getAttribute('data-id');
document.querySelector(`input[name='attachment-del-${uuid}']`).value = 'true';
document.querySelector(`input[name='attachment-del-${uuid}']`).value =
'true';
hideElem(`#attachment-${id}`);
});
}
@ -17,6 +18,7 @@ export function initRepoReleaseNew() {
initTagNameEditor();
initRepoReleaseEditor();
initAddExternalLinkButton();
}
function initTagNameEditor() {
@ -45,9 +47,49 @@ function initTagNameEditor() {
}
function initRepoReleaseEditor() {
const editor = document.querySelector('.repository.new.release .combo-markdown-editor');
const editor = document.querySelector(
'.repository.new.release .combo-markdown-editor',
);
if (!editor) {
return;
}
initComboMarkdownEditor(editor);
}
let newAttachmentCount = 0;
function initAddExternalLinkButton() {
const addExternalLinkButton = document.getElementById('add-external-link');
if (!addExternalLinkButton) return;
addExternalLinkButton.addEventListener('click', () => {
newAttachmentCount += 1;
const attachmentTemplate = document.getElementById('attachment-template');
const newAttachment = attachmentTemplate.cloneNode(true);
newAttachment.id = `attachment-N${newAttachmentCount}`;
newAttachment.classList.remove('tw-hidden');
const attachmentName = newAttachment.querySelector(
'input[name="attachment-template-new-name"]',
);
attachmentName.name = `attachment-new-name-${newAttachmentCount}`;
attachmentName.required = true;
const attachmentExtUrl = newAttachment.querySelector(
'input[name="attachment-template-new-exturl"]',
);
attachmentExtUrl.name = `attachment-new-exturl-${newAttachmentCount}`;
attachmentExtUrl.required = true;
const attachmentDel = newAttachment.querySelector('.remove-rel-attach');
attachmentDel.addEventListener('click', () => {
newAttachment.remove();
});
attachmentTemplate.parentNode.insertBefore(
newAttachment,
attachmentTemplate,
);
});
}