Created
November 20, 2012 02:49
-
-
Save eduardolundgren/4115614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%-- | |
/** | |
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. | |
* | |
* This library is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU Lesser General Public License as published by the Free | |
* Software Foundation; either version 2.1 of the License, or (at your option) | |
* any later version. | |
* | |
* This library is distributed in the hope that it will be useful, but WITHOUT | |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
* details. | |
*/ | |
--%> | |
<%@ include file="/html/portlet/breadcrumb/init.jsp" %> | |
// 'start', 'complete', 'end', 'success', 'failure', 'progress' | |
<aui:script use="aui-base"> | |
var Lang = A.Lang; | |
var ServiceUtil = { | |
INVOKER_URL: themeDisplay.getPathContext() + '/api/jsonws/invoke', | |
constructor: Service, | |
invoke: function(payload, events, ioConfig) { | |
var instance = this; | |
var ioRequest; | |
events = events || {}; | |
A.Do.before( | |
function(event) { | |
var data = ioRequest.get('responseData'); | |
return new A.Do.AlterArgs(null, [data, event]); | |
}, | |
events, | |
'success' | |
); | |
ioRequest = A.io.request( | |
instance.INVOKER_URL, | |
A.merge( | |
{ | |
cache: false, | |
data: { | |
cmd: A.JSON.stringify(payload), | |
p_auth: Liferay.authToken | |
}, | |
dataType: 'json', | |
on: events | |
}, | |
ioConfig | |
) | |
); | |
return ioRequest; | |
}, | |
parseArgs: function(args) { | |
var instance = this; | |
var events; | |
var ioConfig; | |
var payload = {}; | |
if (Lang.isString(args[0])) { | |
if (Lang.isObject(args[1]) && !Lang.isFunction(args[1])) { | |
payload[args[0]] = args[1]; | |
} | |
} | |
return [ | |
payload, | |
events, | |
ioConfig | |
]; | |
} | |
}; | |
var Service = function() { | |
var instance = this; | |
var args = ServiceUtil.parseArgs(arguments); // [ {...}, { success: ... }, ioConfig ] | |
ServiceUtil.invoke.apply(null, args); | |
}; | |
Liferay.Service1 = Service; | |
</aui:script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment