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

META-INF.resources.js.DDMTemplateElementsDefaultPropsTransformer.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 {openConfirmModal, openModal} from 'frontend-js-web';

const ACTIONS = {
	deleteDDMTemplate(itemData) {
		openConfirmModal({
			message: Liferay.Language.get(
				'are-you-sure-you-want-to-delete-this'
			),
			onConfirm: (isConfirmed) =>
				isConfirmed &&
				submitForm(document.hrefFm, itemData.deleteDDMTemplateURL),
		});
	},

	permissionsDDMTemplate(itemData) {
		openModal({
			title: Liferay.Language.get('permissions'),
			url: itemData.permissionsDDMTemplateURL,
		});
	},
};

export default function propsTransformer({actions, items, ...props}) {
	const updateItem = (item) => {
		const newItem = {
			...item,
			onClick(event) {
				const action = item.data?.action;

				if (action) {
					event.preventDefault();

					ACTIONS[action]?.(item.data);
				}
			},
		};

		if (Array.isArray(item.items)) {
			newItem.items = item.items.map(updateItem);
		}

		return newItem;
	};

	return {
		...props,
		actions: actions?.map(updateItem),
		items: items?.map(updateItem),
	};
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy