summaryrefslogtreecommitdiff
path: root/lib/dojo/rpc
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2010-11-15 10:39:52 +0300
committerAndrew Dolgov <[email protected]>2010-11-15 10:39:52 +0300
commit2f01fe57a8d37767827d6db42850aef86a767c53 (patch)
tree516a95ffce2fc2435aed8d9976e444dbcba7dce3 /lib/dojo/rpc
parent951906dcecb1d3c7bcf751976a03e0c196ca6db0 (diff)
add dijit/dojo stuff; initial ui mockup
Diffstat (limited to 'lib/dojo/rpc')
-rw-r--r--lib/dojo/rpc/JsonService.js37
-rw-r--r--lib/dojo/rpc/JsonpService.js32
-rw-r--r--lib/dojo/rpc/RpcService.js89
3 files changed, 158 insertions, 0 deletions
diff --git a/lib/dojo/rpc/JsonService.js b/lib/dojo/rpc/JsonService.js
new file mode 100644
index 000000000..b88e5f531
--- /dev/null
+++ b/lib/dojo/rpc/JsonService.js
@@ -0,0 +1,37 @@
+/*
+ Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojo.rpc.JsonService"]){
+dojo._hasResource["dojo.rpc.JsonService"]=true;
+dojo.provide("dojo.rpc.JsonService");
+dojo.require("dojo.rpc.RpcService");
+dojo.declare("dojo.rpc.JsonService",dojo.rpc.RpcService,{bustCache:false,contentType:"application/json-rpc",lastSubmissionId:0,callRemote:function(_1,_2){
+var _3=new dojo.Deferred();
+this.bind(_1,_2,_3);
+return _3;
+},bind:function(_4,_5,_6,_7){
+var _8=dojo.rawXhrPost({url:_7||this.serviceUrl,postData:this.createRequest(_4,_5),contentType:this.contentType,timeout:this.timeout,handleAs:"json-comment-optional"});
+_8.addCallbacks(this.resultCallback(_6),this.errorCallback(_6));
+},createRequest:function(_9,_a){
+var _b={"params":_a,"method":_9,"id":++this.lastSubmissionId};
+var _c=dojo.toJson(_b);
+return _c;
+},parseResults:function(_d){
+if(dojo.isObject(_d)){
+if("result" in _d){
+return _d.result;
+}
+if("Result" in _d){
+return _d.Result;
+}
+if("ResultSet" in _d){
+return _d.ResultSet;
+}
+}
+return _d;
+}});
+}
diff --git a/lib/dojo/rpc/JsonpService.js b/lib/dojo/rpc/JsonpService.js
new file mode 100644
index 000000000..68c971207
--- /dev/null
+++ b/lib/dojo/rpc/JsonpService.js
@@ -0,0 +1,32 @@
+/*
+ Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojo.rpc.JsonpService"]){
+dojo._hasResource["dojo.rpc.JsonpService"]=true;
+dojo.provide("dojo.rpc.JsonpService");
+dojo.require("dojo.rpc.RpcService");
+dojo.require("dojo.io.script");
+dojo.declare("dojo.rpc.JsonpService",dojo.rpc.RpcService,{constructor:function(_1,_2){
+if(this.required){
+if(_2){
+dojo.mixin(this.required,_2);
+}
+dojo.forEach(this.required,function(_3){
+if(_3==""||_3==undefined){
+throw new Error("Required Service Argument not found: "+_3);
+}
+});
+}
+},strictArgChecks:false,bind:function(_4,_5,_6,_7){
+var _8=dojo.io.script.get({url:_7||this.serviceUrl,callbackParamName:this.callbackParamName||"callback",content:this.createRequest(_5),timeout:this.timeout,handleAs:"json",preventCache:true});
+_8.addCallbacks(this.resultCallback(_6),this.errorCallback(_6));
+},createRequest:function(_9){
+var _a=(dojo.isArrayLike(_9)&&_9.length==1)?_9[0]:{};
+dojo.mixin(_a,this.required);
+return _a;
+}});
+}
diff --git a/lib/dojo/rpc/RpcService.js b/lib/dojo/rpc/RpcService.js
new file mode 100644
index 000000000..03c6a46b6
--- /dev/null
+++ b/lib/dojo/rpc/RpcService.js
@@ -0,0 +1,89 @@
+/*
+ Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojo.rpc.RpcService"]){
+dojo._hasResource["dojo.rpc.RpcService"]=true;
+dojo.provide("dojo.rpc.RpcService");
+dojo.declare("dojo.rpc.RpcService",null,{constructor:function(_1){
+if(_1){
+if((dojo.isString(_1))||(_1 instanceof dojo._Url)){
+if(_1 instanceof dojo._Url){
+var _2=_1+"";
+}else{
+_2=_1;
+}
+var _3=dojo.xhrGet({url:_2,handleAs:"json-comment-optional",sync:true});
+_3.addCallback(this,"processSmd");
+_3.addErrback(function(){
+throw new Error("Unable to load SMD from "+_1);
+});
+}else{
+if(_1.smdStr){
+this.processSmd(dojo.eval("("+_1.smdStr+")"));
+}else{
+if(_1.serviceUrl){
+this.serviceUrl=_1.serviceUrl;
+}
+this.timeout=_1.timeout||3000;
+if("strictArgChecks" in _1){
+this.strictArgChecks=_1.strictArgChecks;
+}
+this.processSmd(_1);
+}
+}
+}
+},strictArgChecks:true,serviceUrl:"",parseResults:function(_4){
+return _4;
+},errorCallback:function(_5){
+return function(_6){
+_5.errback(_6.message);
+};
+},resultCallback:function(_7){
+var tf=dojo.hitch(this,function(_8){
+if(_8.error!=null){
+var _9;
+if(typeof _8.error=="object"){
+_9=new Error(_8.error.message);
+_9.code=_8.error.code;
+_9.error=_8.error.error;
+}else{
+_9=new Error(_8.error);
+}
+_9.id=_8.id;
+_9.errorObject=_8;
+_7.errback(_9);
+}else{
+_7.callback(this.parseResults(_8));
+}
+});
+return tf;
+},generateMethod:function(_a,_b,_c){
+return dojo.hitch(this,function(){
+var _d=new dojo.Deferred();
+if((this.strictArgChecks)&&(_b!=null)&&(arguments.length!=_b.length)){
+throw new Error("Invalid number of parameters for remote method.");
+}else{
+this.bind(_a,dojo._toArray(arguments),_d,_c);
+}
+return _d;
+});
+},processSmd:function(_e){
+if(_e.methods){
+dojo.forEach(_e.methods,function(m){
+if(m&&m.name){
+this[m.name]=this.generateMethod(m.name,m.parameters,m.url||m.serviceUrl||m.serviceURL);
+if(!dojo.isFunction(this[m.name])){
+throw new Error("RpcService: Failed to create"+m.name+"()");
+}
+}
+},this);
+}
+this.serviceUrl=_e.serviceUrl||_e.serviceURL;
+this.required=_e.required;
+this.smd=_e;
+}});
+}