如何关闭Liferay.util.openWindow弹出窗口?

时间:2012-07-02 11:41:35

标签: liferay-6

我使用以下代码在弹出窗口中加载WebContent编辑portlet:

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

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) + "'});";

保存或发布内容时,将在弹出窗口中加载portlet。我希望弹出窗口关闭,并使用editURL链接刷新portlet。

2 个答案:

答案 0 :(得分:2)

只有在编辑成功并且弹出窗口刷新后,您才能从弹出窗口调用以下javascript函数:

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']
    );

<强>解释

弹出窗口将通过向id: '" + liferayPortletResponse.getNamespace() + "' DialogManager功能提供closeByChild弹出窗口来关闭。

Liferay已经定义了一个实用程序方法来通过ajax刷新portlet,因此你可以将portlet的<div id="p_p_id_MyWCDPortlet_">传递给refresh函数。

因此,当成功更新后弹出窗口刷新时,如果调用函数closePopUpAndRefreshPortlet("customPopUpID"),它首先会自行关闭,然后刷新包含portlet的父<div>

希望这有帮助。

答案 1 :(得分:0)

此页面可能会有所帮助 - How to close a Dialog IFrame in 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>

并在对话框页面内创建按钮触发器(或您的案例中的onsubmit事件监听器)( 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's 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>