-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest.js
59 lines (51 loc) · 1.95 KB
/
request.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* jshint devel:true */
/* global WL */
//---------------------------------------------------------------------------------
// Module: dworklight/request
//---------------------------------------------------------------------------------
define([
"module",
"dojo/_base/lang",
"dojo/Deferred"
], function(module, lang, Deferred) {
var MODULE = module.id;
if ( ! lang.getObject("WL.Client.invokeProcedure") ) {
console.warn(MODULE,": Worklight libraries not available. Any 'wladapter' calls will fail!");
}
//--------------------------------------------------------------------
function request( /*map*/ args ) {
var def = new Deferred();
if ( ! lang.getObject("WL.Client.invokeProcedure") ) {
var err = new Error("Worklight libraries not available. Unable to call 'WL.Client.invokeProcedure'.");
def.reject( err );
} else {
args.options.data = args.options.data || [];
if ( !lang.isArray( args.options.data ) ) {
args.options.data = [ args.options.data ];
}
WL.Client.invokeProcedure({
adapter : args.adapter,
procedure : args.procedure,
parameters : args.options.data
},
{
onSuccess: function(resp) {
//console.log(F,"onSuccess:", resp );
def.resolve(resp.invocationResult);
},
onFailure: function(err) {
def.reject({
status : err.status,
response : err.invocationResult,
errorCode : err.errorCode,
message : err.errorMsg,
env : err.env,
isSuccessful: false
});
}
});
}
return def.promise;
}
return request;
});