useFlyout.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useRoute } from 'vue-router'
  3. import {
  4. closeOverlayContainer,
  5. getOpenedOverlayContainers,
  6. getOverlayContainerMeta,
  7. isOverlayContainerOpened,
  8. openOverlayContainer,
  9. useOverlayContainer,
  10. type OverlayContainerOptions,
  11. } from '#desktop/composables/useOverlayContainer.ts'
  12. import { getCurrentApp } from '#desktop/currentApp.ts'
  13. const OVERLAY_CONTAINER_TYPE = 'flyout'
  14. export const getOpenedFlyouts = () =>
  15. getOpenedOverlayContainers(OVERLAY_CONTAINER_TYPE)
  16. export const isFlyoutOpened = (name?: string) =>
  17. isOverlayContainerOpened(OVERLAY_CONTAINER_TYPE, name)
  18. export const getFlyoutMeta = () => {
  19. const overlayContainerMeta = getOverlayContainerMeta(OVERLAY_CONTAINER_TYPE)
  20. return {
  21. flyoutsOptions: overlayContainerMeta.options,
  22. openedFlyouts: overlayContainerMeta.opened,
  23. }
  24. }
  25. export const openFlyout = async (
  26. name: string,
  27. props: Record<string, unknown>,
  28. global: boolean = false,
  29. ) => {
  30. let currentName = name
  31. if (!global) {
  32. getCurrentApp().runWithContext(() => {
  33. const route = useRoute()
  34. currentName = `${name}_${route.path}`
  35. })
  36. }
  37. return openOverlayContainer(OVERLAY_CONTAINER_TYPE, currentName, props)
  38. }
  39. export const closeFlyout = async (name: string, global: boolean = false) => {
  40. let currentName = name
  41. if (!global) {
  42. getCurrentApp().runWithContext(() => {
  43. const route = useRoute()
  44. currentName = `${name}_${route.path}`
  45. })
  46. }
  47. return closeOverlayContainer(OVERLAY_CONTAINER_TYPE, currentName)
  48. }
  49. export const useFlyout = (options: OverlayContainerOptions) => {
  50. return useOverlayContainer(OVERLAY_CONTAINER_TYPE, options)
  51. }