How to close popup window Liferay.util.openWindow?

I load the WebContent edit portlet in a popup using the following code:

<liferay-ui:icon 
    image="edit" 
    message="Edit" 
    url="<%= editUrl %>"
/>

Value for editUrl:

editUrl = "javascript:Liferay.Util.openWindow({ 
dialog:{
    width: 960, 
    modal:true, 
    destroyOnClose: true
}, 
id: '" + liferayPortletResponse.getNamespace() + "', 
title: '" + article.getTitle(Locale.UK, true) + "', 
uri:'" + HtmlUtil.escapeURL(editPortletURLString) + "'});";

When content is saved or published, the portlet is loaded in a popup window. I want the popup to close and the portlet with the editURL link is updated.

+5
source share
2 answers

You can call the following javascript function from your popup only when editing is successful and the popup is updated:

Liferay.provide(
        window,
        'closePopUpAndRefreshPortlet',
        function(customPopUpId) {

            var A = AUI();

            A.DialogManager.closeByChild('#' + customPopUpId);

            var curPortletBoundaryId = '#p_p_id<portlet:namespace />';

            Liferay.Portlet.refresh(curPortletBoundaryId);
        },
        ['aui-dialog','aui-dialog-iframe']
    );

Explanation

The popup will be closed by providing a id: '" + liferayPortletResponse.getNamespace() + "'popup for the function DialogManager closeByChild.

Liferay ajax, <div id="p_p_id_MyWCDPortlet_"> refresh.

, , closePopUpAndRefreshPortlet("customPopUpID"), , <div>, .

, .

+2

- IFrame Liferay 6.2

, (, view.jsp):

<aui:button name="openDialog" type="button" value="open-dialog" />

    <liferay-portlet:renderURL var="dialogURL" windowState="<%=LiferayWindowState.POP_UP.toString() %>">
        <liferay-portlet:param name="mvcPath" value="/dialog.jsp" />
    </liferay-portlet:renderURL>
    <aui:script use="liferay-util-window">
    A.one('#<portlet:namespace/>openDialog').on('click', function(event) {
        Liferay.Util.openWindow({
            dialog: {
                centered: true,
                height: 300,
                modal: true,
                width: 400
            },
            id: '<portlet:namespace/>dialog',
            title: '<liferay-ui:message key="i-am-the-dialog" />',
            uri: '<%=dialogURL %>'
        });
    });
</aui:script>

( ) (dialog.jsp):

<aui:button name="closeDialog" type="button" value="close" />

<aui:script use="aui-base">
    A.one('#<portlet:namespace/>closeDialog').on('click', function(event) {
        // Let suppose that "data" contains the processing results
        var data = ...
        // Invoke a function with processgin results and dialog id
        Liferay.Util.getOpener().<portlet:namespace/>closePopup(data, '<portlet:namespace/>dialog');
    });
</aui:script>

, getOpener(). , (view.jsp), closePopup :

<aui:script>
    Liferay.provide(
        window,
        '<portlet:namespace/>closePopup',
        function(data, dialogId) {
            var A = AUI();

            // Here you can use "data" parameter

            // Closing the dialog
            var dialog = Liferay.Util.Window.getById(dialogId);
            dialog.destroy();
        },
        ['liferay-util-window']
    );
</aui:script>
0

All Articles