1Liferay = window.Liferay || {}; 2 3(function(A, Liferay) { 4 var Lang = A.Lang; 5 6 var owns = A.Object.owns; 7 8 var isNode = function(node) { 9 return node && (node._node || node.nodeType); 10 }; 11 12 var REGEX_METHOD_GET = /^get$/i; 13 14 Liferay.namespace = A.namespace; 15 16 A.mix( 17 A.namespace('config.io'), 18 { 19 method: 'POST', 20 uriFormatter: function(value) { 21 return Liferay.Util.getURLWithSessionId(value); 22 } 23 }, 24 true 25 ); 26 27 /** 28 * OPTIONS 29 * 30 * Required 31 * service {string|object}: Either the service name, or an object with the keys as the service to call, and the value as the service configuration object. 32 * 33 * Optional 34 * data {object|node|string}: The data to send to the service. If the object passed is the ID of a form or a form element, the form fields will be serialized and used as the data. 35 * successCallback {function}: A function to execute when the server returns a response. It receives a JSON object as it's first parameter. 36 * exceptionCallback {function}: A function to execute when the response from the server contains a service exception. It receives a the exception message as it's first parameter. 37 */ 38 39 var Service = function() { 40 var instance = this; 41 42 var args = Service.parseInvokeArgs(arguments); 43 44 Service.invoke.apply(Service, args); 45 }; 46 47 A.mix( 48 Service, 49 { 50 URL_INVOKE: themeDisplay.getPathContext() + '/api/jsonws/invoke', 51 52 bind: function() { 53 var instance = this; 54 55 var args = A.Array(arguments, 0, true); 56 57 args.unshift(Liferay.Service, Liferay); 58 59 return A.bind.apply(A, args); 60 }, 61 62 parseInvokeArgs: function(args) { 63 var instance = this; 64 65 var payload = args[0]; 66 67 var ioConfig = instance.parseIOConfig(args); 68 69 if (Lang.isString(payload)) { 70 payload = instance.parseStringPayload(args); 71 72 instance.parseIOFormConfig(ioConfig, args); 73 74 var lastArg = args[args.length - 1]; 75 76 if (Lang.isObject(lastArg) && lastArg.method) { 77 ioConfig.method = lastArg.method; 78 } 79 } 80 81 return [payload, ioConfig]; 82 }, 83 84 parseIOConfig: function(args) { 85 var instance = this; 86 87 var payload = args[0]; 88 89 var ioConfig = payload.io || {}; 90 91 delete payload.io; 92 93 if (!(ioConfig.on && ioConfig.on.success)) { 94 var callbacks = A.Array.filter(args, Lang.isFunction); 95 96 var callbackSuccess = callbacks[0]; 97 var callbackException = callbacks[1]; 98 99 if (!callbackException) { 100 callbackException = callbackSuccess; 101 } 102 103 A.namespace.call(ioConfig, 'on'); 104 105 ioConfig.on.success = function(event) { 106 var responseData = this.get('responseData'); 107 108 if ((responseData !== null) && !owns(responseData, 'exception')) { 109 if (callbackSuccess) { 110 callbackSuccess.call(this, responseData); 111 } 112 } 113 else if (callbackException) { 114 var exception = responseData ? responseData.exception : 'The server returned an empty response'; 115 116 callbackException.call(this, exception, responseData); 117 } 118 }; 119 } 120 121 if (!owns(ioConfig, 'cache') && REGEX_METHOD_GET.test(ioConfig.method)) { 122 ioConfig.cache = false; 123 } 124 125 if (Liferay.PropsValues.NTLM_AUTH_ENABLED && Liferay.Browser.isIe()) { 126 ioConfig.method = 'GET'; 127 } 128 129 return ioConfig; 130 }, 131 132 parseIOFormConfig: function(ioConfig, args) { 133 var instance = this; 134 135 var form = args[1]; 136 137 if (isNode(form)) { 138 A.namespace.call(ioConfig, 'form'); 139 140 ioConfig.form.id = form._node || form; 141 } 142 }, 143 144 parseStringPayload: function(args) { 145 var instance = this; 146 147 var params = {}; 148 var payload = {}; 149 150 var config = args[1]; 151 152 if (!Lang.isFunction(config) && !isNode(config)) { 153 params = config; 154 } 155 156 payload[args[0]] = params; 157 158 return payload; 159 } 160 }, 161 true 162 ); 163 164 Liferay.provide( 165 Service, 166 'invoke', 167 function(payload, ioConfig) { 168 var instance = this; 169 170 A.io.request( 171 instance.URL_INVOKE, 172 A.merge( 173 { 174 data: { 175 cmd: A.JSON.stringify(payload), 176 p_auth: Liferay.authToken 177 }, 178 dataType: 'json' 179 }, 180 ioConfig 181 ) 182 ); 183 }, 184 ['aui-io-request'] 185 ); 186 187 A.each( 188 ['get', 'delete', 'post', 'put', 'update'], 189 function(item, index, collection) { 190 var methodName = item; 191 192 if (item === 'delete') { 193 methodName = 'del'; 194 } 195 196 Service[methodName] = A.rbind( 197 'Service', 198 Liferay, 199 { 200 method: item 201 } 202 ); 203 } 204 ); 205 206 Liferay.Service = Service; 207 208 var components = {}; 209 var componentsFn = {}; 210 211 Liferay.component = function(id, value) { 212 var retVal; 213 214 if (arguments.length === 1) { 215 var component = components[id]; 216 217 if (component && Lang.isFunction(component)) { 218 componentsFn[id] = component; 219 220 component = component(); 221 222 components[id] = component; 223 } 224 225 retVal = component; 226 } 227 else { 228 retVal = (components[id] = value); 229 } 230 231 return retVal; 232 }; 233 234 Liferay._components = components; 235 Liferay._componentsFn = components; 236 237 Liferay.Template = { 238 PORTLET: '<div class="portlet"><div class="portlet-topper"><div class="portlet-title"></div></div><div class="portlet-content"></div><div class="forbidden-action"></div></div>' 239 }; 240})(AUI(), Liferay);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.