import { computed, defineComponent, ref } from 'vue'; import Modal from './_modal'; import type { BCMSWhereIsItUsedModalInputData, BCMSWhereIsItUsedModalOutputData, BCMSModalInputDefaults, BCMSWhereIsItUsedItem, } from '../../types'; import BCMSLink from '../link'; import BCMSIcon from '../icon'; import { useRouter } from 'vue-router'; import { useTranslation } from '../../translations'; interface Data extends BCMSModalInputDefaults { colsVisible: { type: boolean; label: boolean; location: boolean; }; items: BCMSWhereIsItUsedItem[]; } const component = defineComponent({ setup() { const translations = computed(() => { return useTranslation(); }); const router = useRouter(); const show = ref(false); const modalData = ref(getData()); window.bcms.modal.whereIsItUsed = { hide() { show.value = false; }, show(data) { modalData.value = getData(data); show.value = true; }, }; function getData(inputData?: BCMSWhereIsItUsedModalInputData): Data { const d: Data = { title: translations.value.modal.whereIsItUsed.title, items: [], colsVisible: { type: true, label: true, location: true, }, onCancel() { // ... }, onDone() { // ... }, }; if (inputData) { if (inputData.title) { d.title = inputData.title; } if (inputData.onDone) { d.onDone = inputData.onDone; } if (inputData.onCancel) { d.onCancel = inputData.onCancel; } if (inputData.colsVisible) { d.colsVisible = { type: !!inputData.colsVisible.type, label: !!inputData.colsVisible.label, location: !!inputData.colsVisible.location, }; } d.items = inputData.items; } return d; } function cancel() { if (modalData.value.onCancel) { const result = modalData.value.onCancel(); if (result instanceof Promise) { result.catch((error) => { console.error(error); }); } } window.bcms.modal.whereIsItUsed.hide(); } function done() { if (modalData.value.onDone) { const result = modalData.value.onDone(); if (result instanceof Promise) { result.catch((error) => { console.error(error); }); } } window.bcms.modal.whereIsItUsed.hide(); } return () => { return ( {modalData.value.items.length > 0 ? (
    {modalData.value.items.map((item) => { return (
  • {modalData.value.colsVisible.type ? (
    {window.bcms.util.string.toPretty(item.type)}
    ) : ( '' )} {modalData.value.colsVisible.label ? (
    {item.label}
    ) : ( '' )} {modalData.value.colsVisible.location ? (
    {item.type === 'entry' ? ( { event.preventDefault(); cancel(); router.push( '/' + (event.currentTarget as HTMLLinkElement).href .split('/') .slice(3) .join('/') ); }} href={`/dashboard/t/${item.template?.id}/e/${item.id}`} class="inline-flex text-green font-semibold no-underline items-center hover:underline focus:underline xs:flex dark:text-yellow" > {item.linkText || translations.value.modal.whereIsItUsed.table .openCta} ) : item.type === 'widget' ? ( { event.preventDefault(); cancel(); router.push( '/' + (event.currentTarget as HTMLLinkElement).href .split('/') .slice(3) .join('/') ); }} href={`/dashboard/w/${item.id}`} class="inline-flex text-green font-semibold no-underline items-center hover:underline focus:underline xs:flex dark:text-yellow" > { translations.value.modal.whereIsItUsed.table .openCta } ) : item.type === 'group' ? ( { event.preventDefault(); cancel(); router.push( '/' + (event.currentTarget as HTMLLinkElement).href .split('/') .slice(3) .join('/') ); }} href={`/dashboard/g/${item.id}`} class="inline-flex text-green font-semibold no-underline items-center hover:underline focus:underline xs:flex dark:text-yellow" > { translations.value.modal.whereIsItUsed.table .openCta } ) : item.type === 'template' ? ( { event.preventDefault(); cancel(); router.push( '/' + (event.currentTarget as HTMLLinkElement).href .split('/') .slice(3) .join('/') ); }} href={`/dashboard/t/${item.id}`} class="inline-flex text-green font-semibold no-underline items-center hover:underline focus:underline xs:flex dark:text-yellow" > { translations.value.modal.whereIsItUsed.table .openCta } ) : ( '' )}
    ) : ( '' )}
  • ); })}
) : (
{translations.value.modal.whereIsItUsed.empty}
)}
); }; }, }); export default component;