Showing posts with label iframe dialog. Show all posts
Showing posts with label iframe dialog. Show all posts

Thursday, June 12, 2014

Liferay 6.2 AUI Dialog / Liferay Popup Window

Introduction:

Liferay 6.2 uses the AUI 2.0 version before liferay version used AUI 1.x.
When come to Liferay 6.2 some of AUI modules was deprecated and new modules was developed.

 Liferay 6.1 version we have different way to create AUI dialog windows and close the windows. The same code might not work in Liferay 6.2 because AUI was upgraded to AUI 2.x in liferay 6.2

Liferay have created another Util java scrip module that is liferay-util-window to create dialog windows or pop up in liferay.

Read following article know more about AUI migration to 2.x version


Read below article for AUI Dialogs in Liferay 6.1



We have two types of AUI Dialogs
  1. Simple AUI Dialog
  2. IFRAME AUI Dialog

Simple AUI Dialog

Simple AUI Dialog cannot accommodate any actions after render the window means we cannot perform any action in the dialog/popup. We need to use only AJAX calls in the dialog/popup.

The following is sample code for AUI Dialog


var popUpWindow=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
//cssClass: 'yourCSSclassName',
modal: true,
resizable: false,
width: 475
}
}
).plug(
A.Plugin.IO,
{
autoLoad: false
}).render();
popUpWindow.show();
popUpWindow.titleNode.html("Liferay 6.2 Dialog Window");
popUpWindow.io.set('uri','<%=simpleDialogExample%>');
popUpWindow.io.start();


Note:

When we work with Dialogs/Popup window state should be pop_up/exclusive state.

When we work with simple dialog use AJAX calls to perform any action.

IFRAME AUI Dialog

Iframe dialog render content in Iframe so we can perform any action in the window. We can perform action URL and Render URL calls.

The following is sample code for Iframe AUI Dialog


var popUpWindow=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
//cssClass: 'yourCSSclassName',
modal: true,
resizable: false,
width: 500
}
}
).plug(
A.Plugin.DialogIframe,
{
autoLoad: true,
iframeCssClass: 'dialog-iframe',
uri:'<%=simpleDialogIframeExample.toString()%>'
}).render();
popUpWindow.show();
popUpWindow.titleNode.html("Liferay 6.2 Iframe Dialog Window");
popUpWindow.io.start();


Open Portlet in AUI Dialog

We can open portlet in AUI dialog. If the portlet have any action then use Iframe dialog.
If the portlet have all AJAX calls inside then use Simple AUI Dialog.

When we open portlet in AUI Dialog we need to create render URL with pop_up/exclusive window state. In the URL creation we need to portlet ID so that URL pointing to respective portlet.

Open Portlet in AUI Dialog/ Window Pop Up


var url =Liferay.PortletURL.createRenderURL();
url.setPortletId("58")  //58 is sign in portlet ID
url.setWindowState('pop_up');
var popUpWindow=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
//cssClass: 'yourCSSclassName',
modal: true,
resizable: false,
width: 500
}
}
).plug(
A.Plugin.DialogIframe,
{
autoLoad: false,
iframeCssClass: 'dialog-iframe',
uri:url.toString()
}).render();
popUpWindow.show();
popUpWindow.titleNode.html("Liferay 6.2 Open Portlet in Iframe Dialog Window");
popUpWindow.io.start();


The following are complete code in JSP Pages

Simple AUI Dialog


<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<portlet:renderURL var="simpleDialogExample"
windowState="<%=LiferayWindowState.EXCLUSIVE.toString()%>">
<portlet:param name="mvcPath"
value="/html/alloyuidialog/simple_alloyui_dialog-content.jsp"/>
<portlet:param name="message" value="Hello welcome"/>
</portlet:renderURL>
<a href="<portlet:renderURL />">&laquo;Home</a>
<div class="separator"></div>
<div>
<h1>Simple AUI Dialog Please click on button  and see </h1><br/>
<aui:button name="simple-dialog-example"  id="simple-dialog-example"
value="Click Here See Simple Allou UI Dialog"> </aui:button>
</div>
<aui:script>
AUI().use('aui-base',
'aui-io-plugin-deprecated',
'liferay-util-window',
function(A) {
A.one('#<portlet:namespace />simple-dialog-example').on('click', function(event){
var popUpWindow=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
//cssClass: 'yourCSSclassName',
modal: true,
resizable: false,
width: 475
}
}
).plug(
A.Plugin.IO,
{
autoLoad: false
}).render();
popUpWindow.show();
popUpWindow.titleNode.html("Liferay 6.2 Dialog Window");
popUpWindow.io.set('uri','<%=simpleDialogExample%>');
popUpWindow.io.start();

});
});
</aui:script>


Iframe AUI Dialog


<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<portlet:renderURL var="simpleDialogIframeExample"
windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="mvcPath"
value="/html/alloyuidialog/iframe_alloyui_dialog_example.jsp"/>
</portlet:renderURL>
<a href="<portlet:renderURL />">&laquo;Home</a>
<div class="separator"></div>
<div>
<h1>Iframe AUI Dialog Please click on button  and see </h1><br/>
<aui:button name="dialog-iframe-example"  id="dialog-iframe-example"
value="Click Here See Ifame Allou UI Dialog"> </aui:button>
</div>
<aui:script>
AUI().use('aui-base',
'aui-io-plugin-deprecated',
'liferay-util-window',
'aui-dialog-iframe-deprecated',
function(A) {
A.one('#<portlet:namespace />dialog-iframe-example').on('click', function(event){
var popUpWindow=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
//cssClass: 'yourCSSclassName',
modal: true,
resizable: false,
width: 500
}
}
).plug(
A.Plugin.DialogIframe,
{
autoLoad: true,
iframeCssClass: 'dialog-iframe',
uri:'<%=simpleDialogIframeExample.toString()%>'
}).render();
popUpWindow.show();
popUpWindow.titleNode.html("Liferay 6.2 Iframe Dialog Window");
popUpWindow.io.start();

});
});
</aui:script>


Open Portlet in AUI Dialog


<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<a href="<portlet:renderURL />">&laquo;Home</a>
<div class="separator"></div>
<div>
<h1>Iframe Dialog Please click on button  and see </h1><br/>
<aui:button name="open-portlet-dialog-iframe-example"
id="open-portlet-dialog-iframe-example" 
value="Click Here See Ifame Allou UI Dialog">
</aui:button>
</div>
<aui:script>
AUI().use('aui-base',
'aui-io-plugin-deprecated',
'liferay-util-window',
'liferay-portlet-url',
'aui-dialog-iframe-deprecated',
function(A) {
A.one('#<portlet:namespace />open-portlet-dialog-iframe-example').on('click',
function(event){
var url =Liferay.PortletURL.createRenderURL();
url.setPortletId("58")  //58 is sign in portlet ID
url.setWindowState('pop_up');
var popUpWindow=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
//cssClass: 'yourCSSclassName',
modal: true,
resizable: false,
width: 500
}
}
).plug(
A.Plugin.DialogIframe,
{
autoLoad: false,
iframeCssClass: 'dialog-iframe',
uri:url.toString()
}).render();
popUpWindow.show();
popUpWindow.titleNode.html("Liferay 6.2 Open Portlet in Iframe Dialog Window");
popUpWindow.io.start();

});
});
</aui:script>


Some More Information About Liferay Dialogue Window

view.jsp




<h1> This is sample liferay Dailog Window Content</h1>

<portlet:renderURL var="simpleDialogExample"
windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="mvcPath" value="/html/alloyuidialog/sample_alloyui_dialog_example.jsp"/>
</portlet:renderURL>

<button type="button" id="<portlet:namespace/>OpenPopUP">Open Liferay PopUp</button>

<script>
window.<portlet:namespace/>LiferayDialogWindowPopUP = null;
AUI().use('aui-base','aui-io-plugin-deprecated','liferay-util-window',function(A) {
A.one('#<portlet:namespace/>OpenPopUP').on('click',function(){
<portlet:namespace />LiferayDialogWindowPopUP=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
cssClass: 'my-liferay-popup',
modal: true,
resizable: false,
//destroyOnClose:true,
destroyOnHide:true,
width:700, 
height:400,
after: {
destroy: function(event) {
console.log("function which  will call after close the dialog");
},
},
}
}
).plug(
A.Plugin.IO,
{
autoLoad: false
}).render();
window.<portlet:namespace />LiferayDialogWindowPopUP.show();
window.<portlet:namespace />LiferayDialogWindowPopUP.titleNode.html("My Dialogue");
window.<portlet:namespace />LiferayDialogWindowPopUP.io.set('uri','<%=simpleDialogExample%>');
window.<portlet:namespace />LiferayDialogWindowPopUP.io.start();
});
});
</script>



Closing Pop-up

Closing Pop-up with some Button this button will be in pop jsp page(sample_alloyui_dialog_example.jsp)

sample_alloyui_dialog_example.jsp



<h1> This is sample liferay Dailog Window Content</h1>

<button type="button"  onclick='<portlet:namespace />closeLiferayPopUP()'></button>

<script>

function <portlet:namespace />closeLiferayPopUP(){
if(window.<portlet:namespace/>LiferayDialogWindowPopUP) {
window.<portlet:namespace/>LiferayDialogWindowPopUP.hide();
}
}
</script>


To execute some task after close pop up then use following code



<portlet:namespace />LiferayDialogWindowPopUP=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
cssClass: 'my-liferay-popup',
modal: true,
resizable: false,
//destroyOnClose:true,
destroyOnHide:true,
width:700,
height:400,
after: {
destroy: function(event) {
console.log("function which  will call after close the dialog");
},
},
}
}
).plug(
A.Plugin.IO,
{
autoLoad: false
}).render();



Download Liferay 6.2 AUI Dialog/PopUP Portlet





Environment:

Liferay IDE 2.x+Eclipse (Kepler) +Liferay Plugins SDK 6.2+Tomcat 7.x Liferay Portal Bundle

Deployment and its Working.

Download portlet you can source or war file to deploy into liferay portal as your convenient.

Once portlet successfully deployed drag the portlet in any desired page. Portlet is available in sample category name as Liferay6.2PopUP.

Portlet Screens:

Default Page


Liferay AUI Dialog


Reference Links





Author

Sunday, November 10, 2013

Working with Liferay Alloy UI Dialogs

Working with Liferay Alloy UI Dialogs


Liferay provides alloy ui dialog which is usefull in many scenarios.

Example:

Open some form in pop up
Show some images in pop up.
Show entire port let in pop up.

Download Liferay Alloy UI Dialog portlet from following location

You can find source and war file


Note:  Portlet developed in Liferay 6.1GA2 EE version

If you want deploy in CE version you just do changes in liferay-plugin-package.properties

Liferay 6.1 EE version

name=LiferayAlloyUIDialog
module-group-id=liferay-ee
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.liferay.com
author=Liferay, Inc.
licenses=EE
liferay-versions=6.1.20

Liferay 6.1 CE version

name = LiferayAlloyUIDialog
module-group-id=liferay
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.liferay.com
author=Liferay, Inc.
licenses=LGPL
liferay-versions=6.1.1

Alloy UI is providing dialog so that we can use in above scenarios

We have two types of Dialogs

Simple Alloy UI dialog
Iframe Dialog

Simple Alloy UI dialog:

In the simple alloy ui dialog we can show something like images and some content. In the dialog we can’t perform any action like render request action or action request action within dialog.
We can perform Ajax calls within dialog. So we can perform Ajax calls using AUI IO request or simple Jquery Ajax method.

Except Ajax cal we can’t perform any action if we perform dialog will be gone.
Means if the page is refreshing in side dialog then dialog will be disappeared. So make sure in simple dialog page should not be refresh means only Ajax call is way to perform some actions in dialog.

The following alloy ui module is required to make use of simple dialog

  aui-dialog
  aui-io

 The following is sample code to use dialog

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<portlet:renderURL var="simpleDialogExample" windowState="<%=LiferayWindowState.EXCLUSIVE.toString()%>">
<portlet:param name="mvcPath" value="/html/alloyuidialog/simple_alloyui_dialog_example.jsp"/>
</portlet:renderURL>
<div>
<aui:button name="simple-dialog-example"  id="simple-dialog-example"  value="Click Here See Simple Allou UI Dialog"> </aui:button>
</div>
<aui:script>
AUI().use('aui-base', function(A) {
A.one('#<portlet:namespace />simple-dialog-example').on('click', function(event){
AUI().use('aui-dialog', 'aui-io', function(A) {
    var dialog = new A.Dialog({
    title: 'Upload Details',
    centered: true,
    modal: true,
    width: 500,
    height: 400,
    }).plug(A.Plugin.IO, {uri: '<%=simpleDialogExample%>'}).render();

});
});
});
</aui:script>

Here we are using aui-dialog module and aui-io module.

Here we have some options
Title: title of dialog
Width: width of dialog
Height: high of dialog
Uri: Rrender URL or Action URL making sure window state should be pop_up or exclusive.
Here observe we have to plug the plug-in called IO plug-in.

Iframe Dialog:

Iframe dialog is something different from simple dialog. In this dialog we can perform any action like normal page. Means we can use action URL to render URL.
If page refresh also we can do its some thigh like normal page in browser.
To make Iframe dialog we need to add following alloy ui modules.

aui-dialog
aui-dialog-iframe
Need to plug DialogIframe  plug-in

The following is example code:

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<portlet:renderURL var="simpleDialogIframeExample" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="mvcPath" value="/html/alloyuidialog/iframe_alloyui_dialog_example.jsp"/>
</portlet:renderURL>
<div>
<h1>Iframe Dialog Plese click on button  and see </h1><br/>
<aui:button name="dialog-iframe-example"  id="dialog-iframe-example"  value="Click Here See Ifame Allou UI Dialog"> </aui:button>
</div>
<aui:script>
AUI().use('aui-base', function(A) {
A.one('#<portlet:namespace />dialog-iframe-example').on('click', function(event){
AUI().use('aui-dialog','aui-dialog-iframe', function(A) {
    var dialog = new A.Dialog({
    title: 'Iframe Dialog',
    centered: true,
    modal: true,
    width: 500,
    height: 400,
    }).plug(A.Plugin.DialogIframe, {
    uri: '<%=simpleDialogIframeExample%>',
    iframeCssClass: 'dialog-iframe',
    }).render();

});
});
});
</aui:script>


Open port let in Iframe Dialog:

When we get requirement to open port let in dialog we can use ifrmae dialog.
We need create URL where we need to pass portlet id or portlet name in URL and window state should be pop_up or exclusive.

The following is url for sample

<liferay-portlet:renderURL portletName="20" var="openPortletURL" varImpl="openPortletURL" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
</liferay-portlet:renderURL>

In the URL port let name is 20 is documents and media portlet.

How to find portlet Id or p_p_id or portlet Name

When you drag and drop port let click on portlet maximize button which is in right side corner of every portlet.




Once it maximized the see url in browser address and find p_p_id this is called portlet id or portlet name.



The following is complete code snippet for open portlet in iframe dialog


<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<liferay-portlet:renderURL portletName="20" var="openPortletURL" varImpl="openPortletURL" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
</liferay-portlet:renderURL>
<div>
<h1>Iframe Dialog Plese click on button  and see Announcement portlet in dialog..</h1><br/>
<aui:button name="portlet-iframe-example"  id="portlet-iframe-example"  value="Open Portlet In Iframe Dailog"> </aui:button>
</div>
<aui:script>
AUI().use('aui-base', function(A) {
A.one('#<portlet:namespace />portlet-iframe-example').on('click', function(event){
AUI().use('aui-dialog','aui-dialog-iframe', function(A) {
    var dialog = new A.Dialog({
    title: 'Iframe Dialog',
    centered: true,
    modal: true,
    width: 500,
    height: 400,
    }).plug(A.Plugin.DialogIframe, {
    uri: '<%=openPortletURL%>',
    iframeCssClass: 'dialog-iframe',
    }).render();

});
});
});
</aui:script>


 Close Dialog


<input type="button" name="close PopUp window" onClick="javascript:closeAuiPopUp();"/>
<aui:script>
function closeAuiPopUp(){
        top.document.getElementById('closethick').click();
}
</aui:script>


Call Some Function when dialog Close

<aui:script>
AUI().use('aui-base', function(A) {
A.one('#<portlet:namespace />simple-dialog-example').on('click', function(event){
AUI().use('aui-dialog', 'aui-io', function(A) {
    var dialog = new A.Dialog({
    title: 'Simple Alloy UI Dailog',
    centered: true,
    modal: true,
    width: 500,
    height: 400,
    on: {
            close: function() {
               alert("Hi You are closing Dialog");
               //mytestfunction();
           }
        },
    }).plug(A.Plugin.IO, {uri: '<%=simpleDialogExample%>'}).render();

});
});
});
</aui:script>

Important Points


  •  We have two types of dialogs simple dialog and ifrmae dialog.
  • Simple dialog we can’t perform page refresh actions only we can perform ajax call. This Ajax call we can use jQuery Ajax or alloy ui io module.
  •  If we want create simple dialog we have to use aui-dailog ,aui-io module and we have to plug IO plug-in.
  • Iframe dialog we can do any actions inside dialog.
  • If we want create iframe dialog we have to use aui-dailog,aui-dailog-iframe modules and plug DialogIframe plugin.
  • We can open complete portlet in iframe dialog for this we have create URL we need to pass p_p_id means port let id .
  • For all above scenarios portlet state should be pop_up or exclusive.

Screen1:


Screen2



Screen3


Screen4



Working with Liferay 6.2

Liferay have util.js in portal there we can have function openWindow for dialog windows.

The following sample code


<portlet:renderURL var="simpleDialogExample" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="mvcPath" value="/html/liferayauidialog/dialogpage.jsp"/>
</portlet:renderURL>


Liferay.Util.openWindow(
{
title: 'Example Dialog',
uri: '<%= simpleDialogExample.toString() %>',
width:500,
height:300,
});



Liferay 6.2 is using aui 2.0 so we have aui-model instead of dialog and have a look into following link

The following is sample code


<%@ include file="init.jsp" %>
<style>
#modal-content{
display:none;
}
</style>
<div>
<aui:button name="simple-dialog-example"  id="simple-dialog-example"  value="Click Here See Simple Allou UI Dialog"> </aui:button>
</div>
 <div id="modal"></div>
<div id="modal-content">This is test</div>
<aui:script>
AUI().use('aui-base','aui-modal', function(A) {
A.one('#<portlet:namespace />simple-dialog-example').on('click', function(event){
A.one('#modal-content').setStyle('display','block')
    var modal = new A.Modal(
      {
       srcNode : '#modal-content',  //contentBox:#modal-content
        centered: true,
        headerContent: '<h3>Modal header</h3>',
        modal: true,
        render: '#modal',
        width: 450
      }
    ).render();
});
});
</aui:script>


Liferay 6.2 AUI Model Portlet Download


AUI Model API Reference




Reference links:



Author: Meera Prince



Recent Posts

Recent Posts Widget

Popular Posts