META-INF.resources.edit_cp_definition_option_rel.jsp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.commerce.product.definitions.web
Show all versions of com.liferay.commerce.product.definitions.web
Liferay Commerce Product Definitions Web
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
*/
--%>
<%@ include file="/init.jsp" %>
<%
CPDefinitionOptionRelDisplayContext cpDefinitionOptionRelDisplayContext = (CPDefinitionOptionRelDisplayContext)request.getAttribute(WebKeys.PORTLET_DISPLAY_CONTEXT);
CPDefinitionOptionRel cpDefinitionOptionRel = cpDefinitionOptionRelDisplayContext.getCPDefinitionOptionRel();
String name = ParamUtil.getString(request, "name", cpDefinitionOptionRel.getName());
String description = ParamUtil.getString(request, "description", cpDefinitionOptionRel.getDescription());
String commerceOptionTypeKey = ParamUtil.getString(request, "commerceOptionTypeKey", cpDefinitionOptionRel.getCommerceOptionTypeKey());
String infoItemServiceKey = ParamUtil.getString(request, "infoItemServiceKey", cpDefinitionOptionRel.getInfoItemServiceKey());
String priority = ParamUtil.getString(request, "priority", String.valueOf(cpDefinitionOptionRel.getPriority()));
boolean facetable = ParamUtil.getBoolean(request, "facetable", cpDefinitionOptionRel.isFacetable());
boolean required = ParamUtil.getBoolean(request, "required", cpDefinitionOptionRel.isRequired());
boolean skuContributor = ParamUtil.getBoolean(request, "skuContributor", cpDefinitionOptionRel.isSkuContributor());
String priceType = ParamUtil.getString(request, "priceType", cpDefinitionOptionRel.getPriceType());
cpDefinitionOptionRel.setName(name);
cpDefinitionOptionRel.setDescription(description);
cpDefinitionOptionRel.setCommerceOptionTypeKey(commerceOptionTypeKey);
long cpDefinitionOptionRelId = cpDefinitionOptionRelDisplayContext.getCPDefinitionOptionRelId();
String defaultLanguageId = cpDefinitionOptionRelDisplayContext.getCatalogDefaultLanguageId();
%>
[0]
<%
for (CommerceOptionType commerceOptionType : cpDefinitionOptionRelDisplayContext.getCommerceOptionTypes()) {
%>
<%
}
%>
">
<%
for (RelatedInfoItemCollectionProvider relatedInfoItemCollectionProvider : cpDefinitionOptionRelDisplayContext.getRelatedInfoItemCollectionProviders()) {
%>
<%
}
%>
">
<%
String dataSetDisplayId = CommerceProductFDSNames.PRODUCT_OPTION_VALUES;
if (cpDefinitionOptionRel.isPriceTypeStatic()) {
dataSetDisplayId = CommerceProductFDSNames.PRODUCT_OPTION_VALUES_STATIC;
}
%>
var allowedPriceContributorTypeNames =
'<%= StringUtil.merge(CPConstants.PRODUCT_OPTION_PRICE_CONTRIBUTOR_FIELD_TYPES, StringPool.COMMA) %>';
var allowedPriceContributorFieldTypeSelectOptions =
allowedPriceContributorTypeNames.split('<%= StringPool.COMMA %>');
var allowedSkuContributorTypeNames =
'<%= StringUtil.merge(CPConstants.PRODUCT_OPTION_SKU_CONTRIBUTOR_FIELD_TYPES, StringPool.COMMA) %>';
var allowedSkuContributorFieldTypeSelectOptions =
allowedSkuContributorTypeNames.split('<%= StringPool.COMMA %>');
var availableTypeNames =
'<%= cpDefinitionOptionRelDisplayContext.getCommerceOptionTypeKeys() %>';
var availableFieldTypeSelectOptions = availableTypeNames.split(
'<%= StringPool.COMMA %>'
);
var multipleValuesTypeNames =
'<%= StringUtil.merge(CPConstants.PRODUCT_OPTION_MULTIPLE_VALUES_FIELD_TYPES, StringPool.COMMA) %>';
var multipleValuesFieldTypeSelectOptions = multipleValuesTypeNames.split(
'<%= StringPool.COMMA %>'
);
var formFieldTypeSelect = document.getElementById(
' commerceOptionTypeKey'
);
var priceTypeSelect = document.getElementById(' priceType');
var skuContributorInput = document.getElementById(
' skuContributor'
);
var valuesContainer = document.getElementById('values-container');
function checkDDMFormFieldType(event) {
var priceTypeSelectValue =
priceTypeSelect.options[priceTypeSelect.selectedIndex].value;
var skuContributorInputChecked = skuContributorInput.checked;
enableFormFieldTypeSelectOptionValues(availableFieldTypeSelectOptions);
if (priceTypeSelectValue != '') {
enableFormFieldTypeSelectOptionValues(
allowedPriceContributorFieldTypeSelectOptions
);
}
if (skuContributorInputChecked) {
enableFormFieldTypeSelectOptionValues(
allowedSkuContributorFieldTypeSelectOptions
);
}
}
function enableFormFieldTypeSelectOptionValues(array) {
if (
formFieldTypeSelect.value != '' &&
!endsWith(formFieldTypeSelect.value, array)
) {
Liferay.Util.openAlertModal({
message:
' ',
});
return;
}
for (var i = 0; i < formFieldTypeSelect.options.length; i++) {
var formFieldTypeSelectOption = formFieldTypeSelect.options[i];
if (formFieldTypeSelectOption.value == '') {
continue;
}
if (endsWith(formFieldTypeSelectOption.value, array)) {
if (formFieldTypeSelectOption.getAttribute('disabled')) {
formFieldTypeSelectOption.removeAttribute('disabled');
}
continue;
}
formFieldTypeSelectOption.setAttribute('disabled', true);
}
}
function handleFormFieldTypeSelectChanges() {
if (
endsWith(
formFieldTypeSelect.value,
allowedPriceContributorFieldTypeSelectOptions
)
) {
enable(priceTypeSelect);
}
else {
if (priceTypeSelect.value == '') {
disable(priceTypeSelect);
}
else {
Liferay.Util.openAlertModal(
' '
);
return;
}
}
if (
endsWith(
formFieldTypeSelect.value,
allowedSkuContributorFieldTypeSelectOptions
)
) {
enable(skuContributorInput);
}
else {
if (!skuContributorInput.checked) {
disable(skuContributorInput);
}
else {
Liferay.Util.openAlertModal({
message:
' ',
});
return;
}
}
if (
endsWith(
formFieldTypeSelect.value,
multipleValuesFieldTypeSelectOptions
)
) {
valuesContainer.classList.remove('d-none');
}
else {
valuesContainer.classList.add('d-none');
}
}
function disable(element) {
if (!element.getAttribute('disabled')) {
element.setAttribute('disabled', true);
}
}
function enable(element) {
if (element.getAttribute('disabled')) {
element.removeAttribute('disabled');
}
}
function endsWith(value, array) {
value = value.toLowerCase();
for (var i = 0; i < array.length; i++) {
if (value.endsWith(array[i].toLowerCase())) {
return true;
}
}
return false;
}
formFieldTypeSelect.addEventListener(
'change',
handleFormFieldTypeSelectChanges
);
skuContributorInput.addEventListener('change', checkDDMFormFieldType);
priceTypeSelect.addEventListener('change', checkDDMFormFieldType);
handleFormFieldTypeSelectChanges();
Liferay.provide(window, ' selectCollectionProvider', () => {
const portletURL = Liferay.Util.PortletURL.createPortletURL(
'<%= currentURLObj %>',
{
description: document.getElementById(
' description'
).value,
facetable: document.getElementById(' facetable')
.checked,
infoItemServiceKey: document.getElementById(
' infoItemServiceKey'
).value,
name: document.getElementById(' name').value,
priceType: document.getElementById(' priceType')
.value,
priority: document.getElementById(' priority')
.value,
required: document.getElementById(' required')
.checked,
skuContributor: document.getElementById(
' skuContributor'
).checked,
}
);
window.location.replace(portletURL.toString());
});