简体   繁体   English

如何关闭Liferay中的弹出窗口?

[英]How to close a popup window in Liferay?

I load the WebContent edit portlet on a Popup window using the following code: 我使用以下代码在弹出窗口上加载WebContent编辑portlet:

<liferay-ui:icon
    image="edit"
    label="true"
    message="news-edit-url"
    url="${oneNews.newsEditUrl}"
    />

editUrl: editUrl:

taglibEditURL = "javascript:Liferay.Util.openWindow({dialog: {width: 960}," + 
    "id: '" + renderResponse.getNamespace() + "'," +
    "title: '" + LanguageUtil.format(request.getLocale(), "edit-x", HtmlUtil.escape(assetRenderer.getTitle(request.getLocale()))) + "'," +
    "uri:'" + HtmlUtil.escapeURL(editPortletURLString) + "'});";

When the content is saved or published, the portlet is loaded on the popup window. 保存或发布内容时,portlet会加载到弹出窗口中。 I want the popup window to close and the portlet with the editURL link to refresh. 我希望关闭弹出窗口,并刷新带有editURL链接的portlet。

Any help regarding this... 关于此的任何帮助...

Here is the code to close the pop-up, this should be present in the parent page which opens the pop-up: 这是关闭弹出窗口的代码,该代码应该出现在打​​开弹出窗口的父页面中:

Liferay version 6.1 Liferay 6.1版

Liferay.provide(
        window,
        '<portlet:namespace />closePopup',
        function(popupIdToClose) {

            var A = AUI();

            A.DialogManager.closeByChild('#' + popupIdToClose);
        },
        ['aui-base','aui-dialog','aui-dialog-iframe']
    );

Liferay version 6.2 Liferay 6.2版

Liferay.provide(
    window,
    '<portlet:namespace/>closePopup',
        function(popupIdToClose) {

            var popupDialog = Liferay.Util.Window.getById(popupIdToClose);

            popupDialog.destroy();
        },
        ['liferay-util-window']
    );

Here is the code to refresh the portlet which opened the pop-up. 这是刷新打开弹出窗口的portlet的代码。 This should be present in the parent page which opens the pop-up: 这应该出现在打​​开弹出窗口的父页面中:

Liferay.provide(
        window,
        '<portlet:namespace />refreshPortlet',
        function() {

            <%-- refreshing the portlet [Liferay.Util.getOpener().] --%>
            var curPortletBoundaryId = '#p_p_id<portlet:namespace />';

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

It is up to you how to call the closePopup & refreshPortlet functions. 如何调用closePopuprefreshPortlet函数由您决定。 One way is you can let the pop-up refresh and call the closePopup function from the pop-up itself only when the request is successfully processed and then call the refreshPortlet function also from the pop-up. 一种方法是,仅当成功处理请求后,才能让弹出窗口刷新并从弹出窗口本身调用closePopup函数,然后再从弹出窗口中调用refreshPortlet函数。

Here is a code-snippet which would help you to call parent-page functions from the pop-up: 这是一个代码段,可帮助您从弹出窗口调用父页面函数:

Liferay.Util.getOpener().<portlet:namespace />closePopup(popupIdToClose);
Liferay.Util.getOpener().<portlet:namespace />refreshPortlet();

The popupIdToClose is the same id which is used when opening the pop-up as shown: popupIdToClose是打开弹出窗口时使用的相同id ,如下所示:

taglibEditURL = "javascript:"
                +   Liferay.Util.openWindow({"
                +       "dialog: {width: 960},"
                +       "id: '" + renderResponse.getNamespace() + "'," // This is the "popupIdToClose"
                +       "title: '" + LanguageUtil.format(request.getLocale(), "edit-x", HtmlUtil.escape(assetRenderer.getTitle(request.getLocale()))) + "',"
                +       "uri:'" + HtmlUtil.escapeURL(editPortletURLString)
                +       "'}"
                +   ");";

Hope this helps. 希望这可以帮助。

AUI taglib solution for 6.2 version. 适用于6.2版本的AUI taglib解决方案。 No additional JS required. 无需其他JS。

<aui:button cssClass="close-panel" type="cancel" value="close" />

Important part is cssClass="close-panel" . 重要部分是cssClass="close-panel"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM