admin.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. delegate(document, '.filter-subset--with-select select', 'change', ({ target }) => {
  27. target.form.submit();
  28. });
  29. const onDomainBlockSeverityChange = (target) => {
  30. const rejectMediaDiv = document.querySelector('.input.with_label.domain_block_reject_media');
  31. const rejectReportsDiv = document.querySelector('.input.with_label.domain_block_reject_reports');
  32. if (rejectMediaDiv) {
  33. rejectMediaDiv.style.display = (target.value === 'suspend') ? 'none' : 'block';
  34. }
  35. if (rejectReportsDiv) {
  36. rejectReportsDiv.style.display = (target.value === 'suspend') ? 'none' : 'block';
  37. }
  38. };
  39. delegate(document, '#domain_block_severity', 'change', ({ target }) => onDomainBlockSeverityChange(target));
  40. const onEnableBootstrapTimelineAccountsChange = (target) => {
  41. const bootstrapTimelineAccountsField = document.querySelector('#form_admin_settings_bootstrap_timeline_accounts');
  42. if (bootstrapTimelineAccountsField) {
  43. bootstrapTimelineAccountsField.disabled = !target.checked;
  44. if (target.checked) {
  45. bootstrapTimelineAccountsField.parentElement.classList.remove('disabled');
  46. } else {
  47. bootstrapTimelineAccountsField.parentElement.classList.add('disabled');
  48. }
  49. }
  50. };
  51. delegate(document, '#form_admin_settings_enable_bootstrap_timeline_accounts', 'change', ({ target }) => onEnableBootstrapTimelineAccountsChange(target));
  52. ready(() => {
  53. const domainBlockSeverityInput = document.getElementById('domain_block_severity');
  54. if (domainBlockSeverityInput) onDomainBlockSeverityChange(domainBlockSeverityInput);
  55. const enableBootstrapTimelineAccounts = document.getElementById('form_admin_settings_enable_bootstrap_timeline_accounts');
  56. if (enableBootstrapTimelineAccounts) onEnableBootstrapTimelineAccountsChange(enableBootstrapTimelineAccounts);
  57. });