admin.js 2.9 KB

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