5

我使用以下代码在弹出窗口上加载 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。

4

2 回答 2

3

只有在编辑成功并且弹出窗口被刷新时,您才能从弹出窗口中调用以下 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"),它首先会自行关闭,然后刷新<div>包含 portlet 的父级。

希望这可以帮助。

于 2012-07-03T06:06:42.550 回答
0

此页面可能会有所帮助 -如何在 Liferay 6.2 中关闭对话框 IFrame

如果您像这样定义模态窗口(假设在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 )内创建按钮触发器(或在您的情况下为 onsubmit 事件侦听器):

<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>
于 2015-09-09T08:33:11.993 回答