admin.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { delegate } from 'rails-ujs';
  2. import ready from '../mastodon/ready';
  3. const batchCheckboxClassName = '.batch-checkbox input[type="checkbox"]';
  4. delegate(document, '#batch_checkbox_all', 'change', ({ target }) => {
  5. [].forEach.call(document.querySelectorAll(batchCheckboxClassName), (content) => {
  6. content.checked = target.checked;
  7. });
  8. });
  9. delegate(document, batchCheckboxClassName, 'change', () => {
  10. const checkAllElement = document.querySelector('#batch_checkbox_all');
  11. if (checkAllElement) {
  12. checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
  13. checkAllElement.indeterminate = !checkAllElement.checked && [].some.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
  14. }
  15. });
  16. delegate(document, '.media-spoiler-show-button', 'click', () => {
  17. [].forEach.call(document.querySelectorAll('button.media-spoiler'), (element) => {
  18. element.click();
  19. });
  20. });
  21. delegate(document, '.media-spoiler-hide-button', 'click', () => {
  22. [].forEach.call(document.querySelectorAll('.spoiler-button.spoiler-button--visible button'), (element) => {
  23. element.click();
  24. });
  25. });
  26. const onDomainBlockSeverityChange = (target) => {
  27. const rejectMediaDiv = document.querySelector('.input.with_label.domain_block_reject_media');
  28. const rejectReportsDiv = document.querySelector('.input.with_label.domain_block_reject_reports');
  29. if (rejectMediaDiv) {
  30. rejectMediaDiv.style.display = (target.value === 'suspend') ? 'none' : 'block';
  31. }
  32. if (rejectReportsDiv) {
  33. rejectReportsDiv.style.display = (target.value === 'suspend') ? 'none' : 'block';
  34. }
  35. };
  36. delegate(document, '#domain_block_severity', 'change', ({ target }) => onDomainBlockSeverityChange(target));
  37. const onEnableBootstrapTimelineAccountsChange = (target) => {
  38. const bootstrapTimelineAccountsField = document.querySelector('#form_admin_settings_bootstrap_timeline_accounts');
  39. if (bootstrapTimelineAccountsField) {
  40. bootstrapTimelineAccountsField.disabled = !target.checked;
  41. if (target.checked) {
  42. bootstrapTimelineAccountsField.parentElement.classList.remove('disabled');
  43. } else {
  44. bootstrapTimelineAccountsField.parentElement.classList.add('disabled');
  45. }
  46. }
  47. };
  48. delegate(document, '#form_admin_settings_enable_bootstrap_timeline_accounts', 'change', ({ target }) => onEnableBootstrapTimelineAccountsChange(target));
  49. ready(() => {
  50. const domainBlockSeverityInput = document.getElementById('domain_block_severity');
  51. if (domainBlockSeverityInput) onDomainBlockSeverityChange(domainBlockSeverityInput);
  52. const enableBootstrapTimelineAccounts = document.getElementById('form_admin_settings_enable_bootstrap_timeline_accounts');
  53. if (enableBootstrapTimelineAccounts) onEnableBootstrapTimelineAccountsChange(enableBootstrapTimelineAccounts);
  54. });