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

META-INF.resources.page_editor.common.openImageSelector.js Maven / Gradle / Ivy

The 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 {openSelectionModal} from 'frontend-js-components-web';

import {config} from '../app/config/index';

export function openImageSelector(callback, destroyedCallback = null) {
	openSelectionModal({
		onClose: destroyedCallback,
		onSelect: (selectedItem) => {
			const {returnType, value} = selectedItem;

			const selectedImage = {};

			if (returnType === 'URL') {
				selectedImage.title = '';
				selectedImage.url = value;
			}
			else {
				const fileEntry = JSON.parse(value);

				selectedImage.classNameId = fileEntry.classNameId;
				selectedImage.classPK = fileEntry.fileEntryId;
				selectedImage.fileEntryId = fileEntry.fileEntryId;
				selectedImage.title = fileEntry.title;
				selectedImage.url = fileEntry.url;
			}

			callback(selectedImage);
		},
		selectEventName: `${config.portletNamespace}selectImage`,
		title: Liferay.Language.get('select'),
		url: config.imageSelectorURL,
	});
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy