You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo-release.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import $ from 'jquery';
  2. import {hideElem, showElem} from '../utils/dom.js';
  3. import {initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
  4. export function initRepoRelease() {
  5. $(document).on('click', '.remove-rel-attach', function() {
  6. const uuid = $(this).data('uuid');
  7. const id = $(this).data('id');
  8. $(`input[name='attachment-del-${uuid}']`).attr('value', true);
  9. hideElem($(`#attachment-${id}`));
  10. });
  11. }
  12. export function initRepoReleaseNew() {
  13. const $repoReleaseNew = $('.repository.new.release');
  14. if (!$repoReleaseNew.length) return;
  15. initTagNameEditor();
  16. initRepoReleaseEditor();
  17. }
  18. function initTagNameEditor() {
  19. const el = document.getElementById('tag-name-editor');
  20. if (!el) return;
  21. const existingTags = JSON.parse(el.getAttribute('data-existing-tags'));
  22. if (!Array.isArray(existingTags)) return;
  23. const defaultTagHelperText = el.getAttribute('data-tag-helper');
  24. const newTagHelperText = el.getAttribute('data-tag-helper-new');
  25. const existingTagHelperText = el.getAttribute('data-tag-helper-existing');
  26. document.getElementById('tag-name').addEventListener('keyup', (e) => {
  27. const value = e.target.value;
  28. const tagHelper = document.getElementById('tag-helper');
  29. if (existingTags.includes(value)) {
  30. // If the tag already exists, hide the target branch selector.
  31. hideElem('#tag-target-selector');
  32. tagHelper.textContent = existingTagHelperText;
  33. } else {
  34. showElem('#tag-target-selector');
  35. tagHelper.textContent = value ? newTagHelperText : defaultTagHelperText;
  36. }
  37. });
  38. }
  39. function initRepoReleaseEditor() {
  40. const $editor = $('.repository.new.release .combo-markdown-editor');
  41. if ($editor.length === 0) {
  42. return;
  43. }
  44. const _promise = initComboMarkdownEditor($editor);
  45. }