Monday 12 September 2016

How to Close Liferay PopUp in Liferay

Step :1

In "view.jsp"

           <liferay-portlet:renderURL var="dialogURL" windowState="                                                                             <%=LiferayWindowState.POP_UP.toString() %>">

    <liferay-portlet:param name="jspPage" value="/html/dialog.jsp" />
    </liferay-portlet:renderURL>

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

// If you  Click on "openDialog"  button popup will be triggered and opened, in that "content.jsp" content's will be loaded.If you Click on "closeDialog" button  popUp  will be closed



    <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 %>'
    });
    });
  
// this below code will helps to Close the popup, once the action triggered from the child page "content.jsp"

Liferay.provide(
     window,
     'closePopup',
     function(dialogId) {
     var dialog = Liferay.Util.getWindow(dialogId);

     Liferay.fire(
     'closeWindow',
     {
    
     id:'<portlet:namespace/>dialog'
     }
     );
     },
     ['aui-base','liferay-util-window']
     );

    </aui:script>


Step 2:

In "content.jsp"



<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
  
  
    <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

    // Invoke a function with processgin results and dialog id
     Liferay.Util.getOpener().closePopup('<portlet:namespace/>dialog');// this will will call the closePopup fuction in parent page where the popUp is initiated "view.jsp".

    });
    </aui:script>
  

No comments:

Post a Comment