Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lpd 29890 #18

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import java.util.Map;
import java.util.Map;

/**
* @author Fabio Diego Mastrorilli
Expand All @@ -22,15 +24,17 @@ public int doStartTag() throws JspException {
HttpServletRequest httpServletRequest = getRequest();

httpServletRequest.setAttribute(
"liferay-commerce:info-box:actionLabel", _actionLabel);
"liferay-commerce:info-box:actionContext", getActionContext());
httpServletRequest.setAttribute(
"liferay-commerce:info-box:actionTargetId", _actionTargetId);
"liferay-commerce:info-box:actionLabel", getActionLabel());
httpServletRequest.setAttribute(
"liferay-commerce:info-box:actionUrl", _actionUrl);
"liferay-commerce:info-box:actionTargetId", getActionTargetId());
httpServletRequest.setAttribute(
"liferay-commerce:info-box:elementClasses", _elementClasses);
"liferay-commerce:info-box:actionUrl", getActionUrl());
httpServletRequest.setAttribute(
"liferay-commerce:info-box:title", _title);
"liferay-commerce:info-box:elementClasses", getElementClasses());
httpServletRequest.setAttribute(
"liferay-commerce:info-box:title", getTitle());

super.doStartTag();

Expand Down Expand Up @@ -88,6 +92,7 @@ public void setTitle(String title) {
protected void cleanUp() {
super.cleanUp();

_actionContext = null;
_actionLabel = null;
_actionTargetId = null;
_actionUrl = null;
Expand All @@ -109,6 +114,16 @@ protected String getStartPage() {

private static final String _START_PAGE = "/info_box/start.jsp";

public Map<String, Object> getActionContext() {
return _actionContext;
}

public void setActionContext(
Map<String, Object> actionContext) {
_actionContext = actionContext;
}

private Map<String, Object> _actionContext;
private String _actionLabel;
private String _actionTargetId;
private String _actionUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@
<name>info-box</name>
<tag-class>com.liferay.commerce.frontend.taglib.servlet.taglib.InfoBoxTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>actionContext</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>actionLabel</name>
<required>false</required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@
taglib uri="http://liferay.com/tld/clay" prefix="clay" %><%@
taglib uri="http://liferay.com/tld/frontend" prefix="liferay-frontend" %><%@
taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>

<%@ page import="com.liferay.petra.string.StringPool" %><%@
<%@ page import="java.util.Map" %><%@
page import="com.liferay.petra.string.StringPool" %><%@
page import="com.liferay.portal.kernel.util.HashMapBuilder" %><%@
page import="com.liferay.portal.kernel.util.HtmlUtil" %><%@
page import="com.liferay.portal.kernel.util.PortalUtil" %><%@
page import="com.liferay.portal.kernel.util.Validator" %>

<liferay-theme:defineObjects />

<%
Map<String, Object> actionContext = (Map<String, Object>)request.getAttribute("liferay-commerce:info-box:actionContext");
String actionLabel = (String)request.getAttribute("liferay-commerce:info-box:actionLabel");
String actionTargetId = (String)request.getAttribute("liferay-commerce:info-box:actionTargetId");
String actionUrl = (String)request.getAttribute("liferay-commerce:info-box:actionUrl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,32 @@
<%@ include file="/info_box/init.jsp" %>

<%
String linkId = PortalUtil.generateRandomKey(request, "info-box") + "_action-link";
String linkId = HtmlUtil.escape(PortalUtil.generateRandomKey(request, "info-box") + "_action-link");
%>

<div class="info-box<%= Validator.isNotNull(elementClasses) ? StringPool.SPACE + elementClasses : StringPool.BLANK %>">
<header class="header pb-2">
<header class="align-items-center d-flex header justify-content-between pb-2">
<c:if test="<%= Validator.isNotNull(title) %>">
<div class="h5 mb-0 title"><%= HtmlUtil.escape(title) %></div>
</c:if>

<c:if test="<%= Validator.isNotNull(actionLabel) %>">
<c:if test="<%= Validator.isNotNull(actionTargetId) %>">
<%
String href = Validator.isNotNull(actionUrl) ? actionUrl : "#";
%>

<c:if test="<%= Validator.isNotNull(actionTargetId)%>">
<%
href = "#";
%>

<aui:script>
var link = document.getElementById('<%= HtmlUtil.escapeJS(linkId) %>');
var link = document.getElementById('<%= linkId %>');

if (link) {
link.addEventListener('click', (e) => {
e.preventDefault();

Liferay.fire('open-modal', {
id: '<%= HtmlUtil.escapeJS(actionTargetId) %>',
});
Expand All @@ -33,9 +42,30 @@ String linkId = PortalUtil.generateRandomKey(request, "info-box") + "_action-lin
</aui:script>
</c:if>

<c:if test="<%= Validator.isNotNull(actionContext) %>">
<%
href = "#";
%>

<liferay-frontend:component
context='<%=
HashMapBuilder.<String, Object>put(
"title", title
).put(
"url", actionUrl
).putAll(
actionContext
).put(
"linkId", linkId
).build()
%>'
module="{infoBoxHandler} from commerce-frontend-taglib"
/>
</c:if>

<clay:link
href='<%= Validator.isNotNull(actionUrl) ? actionUrl : "#" %>'
id="<%= HtmlUtil.escape(linkId) %>"
href="<%= href %>"
id="<%= linkId %>"
label="<%= HtmlUtil.escape(actionLabel) %>"
/>
</c:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
export {default as searchBar} from './search_bar/SearchBar';
export {default as searchResults} from './search_results/SearchResults';
export {default as discontinuedLabelCPInstanceChangeHandler} from './discontinued_label/DiscontinuedLabelCPInstanceChangeHandler';
export {default as infoBoxHandler} from './info_box';

export function accountSelectorTag({
accountEntryAllowedTypes,
Expand Down Expand Up @@ -199,6 +200,7 @@ export function cart({
cartViews,
checkoutURL,
currencyCode,
detachedOpener,
displayDiscountLevels,
displayTotalItemsQuantity,
groupId,
Expand Down Expand Up @@ -227,6 +229,7 @@ export function cart({
groupId,
id,
},
detachedOpener,
displayDiscountLevels,
displayTotalItemsQuantity,
itemsQuantity: Number(itemsQuantity),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

import {openModal} from 'frontend-js-web';

export default function infoBoxHandler({
containerCssClasses: className = '',
linkId,
modalId = null,
namespace,
size,
refreshOnClose,
title,
url
}) {
const formId = `${namespace}fm`;
const linkElement = document.querySelector(`#${linkId}`);

const handleOpenModal = (event) => {
event.preventDefault();

const id = modalId ?? namespace;

openModal({
buttons: [
{
displayType: 'secondary',
label: Liferay.Language.get('cancel'),
type: 'cancel',
},
{
formId,
label: Liferay.Language.get('submit'),
type: 'submit',
},
],
containerProps: {
className
},
id,
onClose: () => {
if (refreshOnClose) {
const refreshTimeout = setTimeout(() => {
clearTimeout(refreshTimeout);

window.top.location.reload();
}, 200);
}
},
onOpen: ({iframeWindow}) => {
const formElement = iframeWindow.document.querySelector(
`#${formId}`
);

if (formElement) {
const {
[`${namespace}redirect`]: {
value: redirect = null
} = {}
} = formElement;

formElement.addEventListener('submit', () => {
Liferay.fire('closeModal', {
id,
redirect,
});
});
}
},
title,
size,
url,
});
}

linkElement.addEventListener('click', handleOpenModal);

return {
dispose() {
linkElement.removeEventListener('click', handleOpenModal);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ CommerceOrder commerceOrder = commerceOrderEditDisplayContext.getCommerceOrder()

<portlet:actionURL name="/commerce_order/edit_commerce_order" var="editCommerceOrderBillingAddressActionURL" />

<commerce-ui:modal-content
contentCssClasses="p-0"
title='<%= LanguageUtil.get(request, "billing-address") %>'
>
<div class="container-fluid container-fluid-max-xl p-4">
<aui:form action="<%= editCommerceOrderBillingAddressActionURL %>" method="post" name="fm">
<aui:input name="<%= Constants.CMD %>" type="hidden" value="selectBillingAddress" />
<aui:input name="redirect" type="hidden" value="<%= currentURL %>" />
<aui:input name="commerceOrderId" type="hidden" value="<%= commerceOrder.getCommerceOrderId() %>" />

<frontend-data-set:classic-display
Expand All @@ -40,4 +36,4 @@ CommerceOrder commerceOrder = commerceOrderEditDisplayContext.getCommerceOrder()
selectionType="single"
/>
</aui:form>
</commerce-ui:modal-content>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ long deliveryCommerceTermEntryId = commerceOrder.getDeliveryCommerceTermEntryId(

<portlet:actionURL name="/commerce_order/edit_commerce_order" var="editCommerceOrderDeliveryTermsActionURL" />

<commerce-ui:modal-content
title='<%= (deliveryCommerceTermEntryId == 0) ? LanguageUtil.get(request, "delivery-terms") : LanguageUtil.get(request, "edit-delivery-terms") %>'
>
<div class="container-fluid container-fluid-max-xl p-4">
<c:choose>
<c:when test="<%= deliveryTermsEntries.isEmpty() %>">
<clay:row>
Expand Down Expand Up @@ -51,7 +49,6 @@ long deliveryCommerceTermEntryId = commerceOrder.getDeliveryCommerceTermEntryId(

<aui:form action="<%= editCommerceOrderDeliveryTermsActionURL %>" method="post" name="fm">
<aui:input name="<%= Constants.CMD %>" type="hidden" value="updateDeliveryTerms" />
<aui:input name="redirect" type="hidden" value="<%= currentURL %>" />
<aui:input name="commerceOrderId" type="hidden" value="<%= commerceOrder.getCommerceOrderId() %>" />

<aui:select label='<%= LanguageUtil.get(request, "title") %>' name="commerceDeliveryTermId" showEmptyOption="<%= true %>">
Expand Down Expand Up @@ -88,4 +85,4 @@ long deliveryCommerceTermEntryId = commerceOrder.getDeliveryCommerceTermEntryId(
/>
</c:otherwise>
</c:choose>
</commerce-ui:modal-content>
</div>
Loading