All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.article.AssetDisplayPagePreview.js Maven / Gradle / Ivy

There is a newer version: 5.0.181
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

import ClayButton from '@clayui/button';
import ClayDropDown from '@clayui/drop-down';
import {openSelectionModal, sub} from 'frontend-js-web';
import React, {useMemo, useState} from 'react';

import AssetDisplayPageSelector from './AssetDisplayPageSelector';
import PreviewButton from './PreviewButton';

export default function AssetDisplayPagePreview({
	newArticle,
	portletNamespace: namespace,
	previewURL,
	saveAsDraftURL,
	selectAssetDisplayPageEventName,
	selectAssetDisplayPageURL,
	selectSiteEventName,
	siteItemSelectorURL,
	sites,
	sitesCount,
}) {
	const [selectedSite, setSelectedSite] = useState();
	const [active, setActive] = useState(false);
	const [assetDisplayPageSelected, setAssetDisplayPageSelected] = useState();

	const siteInputId = `${namespace}siteInput`;

	const items = useMemo(() => {
		return [
			{groupId: 0, name: `- ${Liferay.Language.get('not-selected')} -`},
			...sites,
		].map((site) => ({
			label: site.name,
			onClick: () => {
				setActive(false);
				setSelectedSite({groupId: site.groupId, name: site.name});

				if (site.groupId !== selectedSite?.groupId) {
					setAssetDisplayPageSelected(null);
				}
			},
		}));
	}, [sites, selectedSite?.groupId]);

	return (
		<>
			
			
						
							{selectedSite?.name ||
								`- ${Liferay.Language.get('not-selected')} -`}
						
					
				}
			>
				{items.map((item) => (
					
						{item.label}
					
				))}

				{sitesCount > sites.length && (
					<>
						
							{sub(
								Liferay.Language.get('showing-x-of-x-items'),
								sites.length,
								sitesCount
							)}
						

						
{ openSelectionModal({ containerProps: { className: 'cadmin', }, onSelect(selectedItem) { setSelectedSite({ groupId: selectedItem.groupid, name: selectedItem.groupdescriptivename, }); }, selectEventName: selectSiteEventName, title: Liferay.Language.get( 'select-site' ), url: siteItemSelectorURL, }); }} size="sm" type="button" > {Liferay.Language.get('more')}
)}
{ const url = new URL(previewURL); url.searchParams.set('classPK', classPK); url.searchParams.set( 'selPlid', assetDisplayPageSelected?.plid ); url.searchParams.set('version', version); return url; }} namespace={namespace} newArticle={newArticle} saveAsDraftURL={saveAsDraftURL} /> ); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy