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

META-INF.resources.js.components.ObjectField.Tabs.Advanced.ReadOnlyContainer.tsx 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 {ClayRadio, ClayRadioGroup} from '@clayui/form';
import {
	ExpressionBuilder,
	SidebarCategory,
} from '@liferay/object-js-components-web';
import classNames from 'classnames';
import React from 'react';

interface ReadOnlyContainerProps {
	disabled?: boolean;
	modelBuilder?: boolean;
	onSubmit?: (values?: Partial) => void;
	readOnlySidebarElements: SidebarCategory[];
	requiredField: boolean;
	setValues: (value: Partial) => void;
	values: Partial;
}

export function ReadOnlyContainer({
	disabled,
	modelBuilder = false,
	onSubmit,
	readOnlySidebarElements,
	requiredField,
	setValues,
	values,
}: ReadOnlyContainerProps) {
	const setReadOnly = (value: ReadOnlyFieldValue) => {
		setValues({
			readOnly: value,
			required:
				value === 'true' || value === 'conditional'
					? false
					: requiredField,
		});
	};

	return (
		
{values.readOnly && ( <> { event.stopPropagation(); if (onSubmit) { onSubmit(); } }} > setReadOnly('true')} value="true" /> setReadOnly('false')} value="false" /> setReadOnly('conditional')} value="conditional" /> {values.readOnly === 'conditional' && ( { event.stopPropagation(); if (onSubmit) { onSubmit(); } }} onChange={({target: {value}}) => { setValues({ readOnlyConditionExpression: value, }); }} onOpenModal={() => { const parentWindow = Liferay.Util.getOpener(); parentWindow.Liferay.fire( 'openExpressionBuilderModal', { eventSidebarElements: readOnlySidebarElements, header: Liferay.Language.get( 'expression-builder' ), onSave: (script: string) => { setValues({ readOnlyConditionExpression: script, }); if (onSubmit) { onSubmit({ ...values, readOnlyConditionExpression: script, }); } }, placeholder: `<#-- ${Liferay.Language.get( 'create-the-condition-of-the-read-only-state-using-expression-builder' )} -->`, required: false, source: values.readOnlyConditionExpression ?? '', validateExpressionURL: '', } ); }} placeholder={Liferay.Language.get( 'create-an-expression' )} value={values.readOnlyConditionExpression ?? ''} /> )} )}
); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy