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.

common-issue.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {updateIssuesMeta} from './repo-issue.js';
  2. export function initCommonIssue() {
  3. $('.issue-checkbox').on('click', () => {
  4. const numChecked = $('.issue-checkbox').children('input:checked').length;
  5. if (numChecked > 0) {
  6. $('#issue-filters').addClass('hide');
  7. $('#issue-actions').removeClass('hide');
  8. } else {
  9. $('#issue-filters').removeClass('hide');
  10. $('#issue-actions').addClass('hide');
  11. }
  12. });
  13. $('.issue-action').on('click', async function () {
  14. let action = this.getAttribute('data-action');
  15. let elementId = this.getAttribute('data-element-id');
  16. const url = this.getAttribute('data-url');
  17. const issueIDs = $('.issue-checkbox').children('input:checked').map((_, el) => {
  18. return el.getAttribute('data-issue-id');
  19. }).get().join(',');
  20. if (elementId === '0' && url.substr(-9) === '/assignee') {
  21. elementId = '';
  22. action = 'clear';
  23. }
  24. updateIssuesMeta(
  25. url,
  26. action,
  27. issueIDs,
  28. elementId
  29. ).then(() => { // eslint-disable-line github/no-then
  30. // NOTICE: This reset of checkbox state targets Firefox caching behaviour, as the
  31. // checkboxes stay checked after reload
  32. if (action === 'close' || action === 'open') {
  33. // uncheck all checkboxes
  34. $('.issue-checkbox input[type="checkbox"]').each((_, e) => { e.checked = false });
  35. }
  36. window.location.reload();
  37. });
  38. });
  39. // NOTICE: This event trigger targets Firefox caching behaviour, as the checkboxes stay
  40. // checked after reload trigger ckecked event, if checkboxes are checked on load
  41. $('.issue-checkbox input[type="checkbox"]:checked').first().each((_, e) => {
  42. e.checked = false;
  43. $(e).trigger('click');
  44. });
  45. }