Liferay.provide 함수에 대한 이해
asynchronous dependency function의 old example is something like:
function incrementNumber(i){
AUI.use('aui-base', function() { i++; });
}
new way to create the exact same function would be:
Liferay.provide(window, 'incrementNumber', function(i){i++;}, ['aui-base']);
advantages : scalability (multiple run), consistency (function will be excuted in the order they are called)
Liferay.provide(obj, methodName, methodFunc, modules)
obj : is the object where to create the method. (If you want to create a global function, obj will be 'window')
methodName : is the name of the method you want to create.
methodFunc : is the function definition as you would normally define it.
modules : is an array of javascript modules that will be loaded before the function is executed.
=> Liferay JSP file에서 Liferay provide 함수를 선언하는 것은 methodFunc 라는 함수를 하나 정의한 것과 같은 기능을 하는 것처럼 보인다. 즉, 함수 선언만 하고 call은 따로 해야된다.
Liferay.Util.openWindow( )
예제
Liferay.provide(
window,
'<portlet:namespace/> openDialogWithPortletUsingJsp',
function() {
var jspUrl = '<%=createAgency.toString()%>';
console.log('JSP URL:' + jspUrl);
Liferay.Util.openWindow({
diaglog: {
headerContent: '<h3>Agency Input</h3>',
cache: false,
destroyOnClose: true,
centered: true,
modal: true,
resizable: false,
width: 770,
height: 370
},
id: '<portlet:namespace/>agencyDialog',
title: '<liferay-ui:message key="Agency Create" />',
url:jspUrl
});
},
['liferay-util-window', 'aui-dialog-iframe-deprecated', 'aui-io-plugin-deprecated', 'liferay-portlet-url', 'aui-node']
);
AUI().ready(function(A) {
AUI().use('aui-dialog', 'aui-io', function(A) {
var url = 'http://localhost/url';
Liferay.Util.openWindow(
{
dialog: {
cache: false,
width:800,
modal: true
},
id:'shahbaj',
uri: url
});
Liferay.provide(
window,
'closePopup',
function(popupIdToClose) {
var dialog = Liferay.Util.getWindow(popupIdToClose);
dialog.destroy(); // You can try toggle/hide whatever You want
},
['aui-base','aui-dialog','aui-dialog-iframe']
);
});
});