registeredActions.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { getElements } from '../util';
  2. /**
  3. * Show/hide registered action checkboxes based on selected object_types.
  4. */
  5. export function initRegisteredActions(): void {
  6. const actionsContainer = document.getElementById('id_registered_actions_container');
  7. const selectedList = document.getElementById('id_object_types_1') as HTMLSelectElement;
  8. if (!actionsContainer || !selectedList) {
  9. return;
  10. }
  11. function updateVisibility(): void {
  12. const selectedModels = new Set<string>();
  13. // Get model keys from selected options
  14. for (const option of Array.from(selectedList.options)) {
  15. const modelKey = option.dataset.modelKey;
  16. if (modelKey) {
  17. selectedModels.add(modelKey);
  18. }
  19. }
  20. // Show/hide action groups
  21. const groups = actionsContainer!.querySelectorAll('.model-actions');
  22. let anyVisible = false;
  23. groups.forEach(group => {
  24. const modelKey = group.getAttribute('data-model');
  25. const visible = modelKey !== null && selectedModels.has(modelKey);
  26. (group as HTMLElement).style.display = visible ? 'block' : 'none';
  27. if (visible) {
  28. anyVisible = true;
  29. }
  30. });
  31. // Show/hide "no actions" message
  32. const noActionsMsg = document.getElementById('no-custom-actions-message');
  33. if (noActionsMsg) {
  34. noActionsMsg.style.display = anyVisible ? 'none' : 'block';
  35. }
  36. }
  37. // Initial update
  38. updateVisibility();
  39. // Listen to move button clicks
  40. for (const btn of getElements<HTMLButtonElement>('.move-option')) {
  41. btn.addEventListener('click', () => {
  42. // Wait for DOM update
  43. setTimeout(updateVisibility, 50);
  44. });
  45. }
  46. }