META-INF.resources.js.article.AssetDisplayPageSelector.js Maven / Gradle / Ivy
/**
* 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 ClayForm, {ClayInput} from '@clayui/form';
import ClayIcon from '@clayui/icon';
import {getPortletNamespace, openSelectionModal, sub} from 'frontend-js-web';
import React from 'react';
export default function AssetDisplayPageSelector({
assetDisplayPageSelected,
disabled = true,
namespace,
selectAssetDisplayPageEventName,
selectAssetDisplayPageURL,
selectedSite,
setAssetDisplayPageSelected,
}) {
const assetDisplayPageId = `${namespace}assetDisplayPageId`;
const openAssetDisplayPageSelector = () => {
const url = new URL(selectAssetDisplayPageURL);
if (selectedSite) {
url.searchParams.set(
`${getPortletNamespace(
Liferay.PortletKeys.ITEM_SELECTOR
)}groupId`,
selectedSite.groupId
);
}
openSelectionModal({
containerProps: {
className: 'cadmin',
},
onSelect(selectedItem) {
let itemValue = selectedItem;
if (
selectedItem.returnType ===
'com.liferay.item.selector.criteria.AssetEntryItemSelectorReturnType'
) {
itemValue = JSON.parse(selectedItem.value);
setAssetDisplayPageSelected({
assetDisplayPageId: itemValue.id,
name: itemValue.name,
plid: itemValue.plid,
});
}
else {
setAssetDisplayPageSelected({
layoutUuid: itemValue.id,
name: itemValue.name,
});
}
},
selectEventName: selectAssetDisplayPageEventName,
title: sub(
Liferay.Language.get('select-x'),
Liferay.Language.get('display-page')
),
url,
});
};
return (
openAssetDisplayPageSelector()}
size="sm"
title={sub(
assetDisplayPageSelected
? Liferay.Language.get('change-x')
: Liferay.Language.get('select-x'),
Liferay.Language.get('display-page')
)}
>
);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy