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

META-INF.resources.edit_template_form.jspf Maven / Gradle / Ivy

There is a newer version: 5.0.110
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
 */
--%>

<%
String namespace = liferayPortletResponse.getNamespace();

if (Validator.isNotNull(portletResourceNamespace)) {
	namespace = portletResourceNamespace;
}

if (Validator.isNull(script)) {
	script = structure.getDefinition();
}

String fieldsJSONArrayString = String.valueOf(_getFormTemplateFieldsJSONArray(structure, script));
%>





	function attachValueChange(formBuilder) {
		var modeInput = document.getElementById('mode');

		if (modeInput) {
			modeInput.addEventListener('change', function (event) {
				toggleMode(formBuilder, event.target.value);
			});
		}
	}

	Liferay.on('formBuilderLoaded', function (event) {
		var formBuilder = event.formBuilder;

		attachValueChange(formBuilder);

		toggleMode(
			formBuilder,
			'<%= HtmlUtil.escape(mode) %>'
		);
	});

	function setFieldsHiddenAttributes(
		formBuilder,
		mode,
		item,
		index
	) {
		var hiddenAttributesMap = formBuilder.MAP_HIDDEN_FIELD_ATTRS;
		var hiddenAttributes =
			hiddenAttributesMap[item.get('type')] || hiddenAttributesMap.DEFAULT;
		var without = function (array) {
			var elems = Array.from(arguments).slice(1);

			elems.forEach(function (value) {
				array = array.filter(function (elem) {
					return elem != value;
				});
			});

			return array;
		};

		if (mode === '<%= DDMTemplateConstants.TEMPLATE_MODE_EDIT %>') {
			hiddenAttributes = without(hiddenAttributes, 'readOnly');
		}

		item.set('hiddenAttributes', hiddenAttributes);
	}

	function toggleMode(formBuilder, mode) {
		var modeEdit = mode === '<%= DDMTemplateConstants.TEMPLATE_MODE_EDIT %>';

		formBuilder.set('allowRemoveRequiredFields', modeEdit);

		var setFieldsHiddenAttributes = setFieldsHiddenAttributes.bind(
			this,
			formBuilder,
			mode
		);
		formBuilder.get('fields')._items.forEach(setFieldsHiddenAttributes);
		formBuilder.get('availableFields').forEach(setFieldsHiddenAttributes);

		var editingField = formBuilder.editingField;

		if (editingField) {
			formBuilder.propertyList.set(
				'data',
				formBuilder.getFieldProperties(editingField, true)
			);
		}
	}

	window['<%= HtmlUtil.escapeJS(namespace) %>getAvailableFields'] = function (
		A,
		FormBuilder
	) {

		<%
		JSONArray structureJSONArray = _getFormTemplateFieldsJSONArray(structure, structure.getDefinition());
		%>

		var availableFields = <%= structureJSONArray.toString() %>;

		availableFields.forEach(function (item, index) {
			item.iconClass = FormBuilder.DEFAULT_ICON_CLASS;
		});

		return availableFields.concat(FormBuilder.AVAILABLE_FIELDS.DDM_TEMPLATE);
	};


<%@ include file="/form_builder.jspf" %>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy