]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/rpc/RpcService.js
add dijit/dojo stuff; initial ui mockup
[tt-rss.git] / lib / dojo / rpc / RpcService.js
CommitLineData
2f01fe57
AD
1/*
2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
5*/
6
7
8if(!dojo._hasResource["dojo.rpc.RpcService"]){
9dojo._hasResource["dojo.rpc.RpcService"]=true;
10dojo.provide("dojo.rpc.RpcService");
11dojo.declare("dojo.rpc.RpcService",null,{constructor:function(_1){
12if(_1){
13if((dojo.isString(_1))||(_1 instanceof dojo._Url)){
14if(_1 instanceof dojo._Url){
15var _2=_1+"";
16}else{
17_2=_1;
18}
19var _3=dojo.xhrGet({url:_2,handleAs:"json-comment-optional",sync:true});
20_3.addCallback(this,"processSmd");
21_3.addErrback(function(){
22throw new Error("Unable to load SMD from "+_1);
23});
24}else{
25if(_1.smdStr){
26this.processSmd(dojo.eval("("+_1.smdStr+")"));
27}else{
28if(_1.serviceUrl){
29this.serviceUrl=_1.serviceUrl;
30}
31this.timeout=_1.timeout||3000;
32if("strictArgChecks" in _1){
33this.strictArgChecks=_1.strictArgChecks;
34}
35this.processSmd(_1);
36}
37}
38}
39},strictArgChecks:true,serviceUrl:"",parseResults:function(_4){
40return _4;
41},errorCallback:function(_5){
42return function(_6){
43_5.errback(_6.message);
44};
45},resultCallback:function(_7){
46var tf=dojo.hitch(this,function(_8){
47if(_8.error!=null){
48var _9;
49if(typeof _8.error=="object"){
50_9=new Error(_8.error.message);
51_9.code=_8.error.code;
52_9.error=_8.error.error;
53}else{
54_9=new Error(_8.error);
55}
56_9.id=_8.id;
57_9.errorObject=_8;
58_7.errback(_9);
59}else{
60_7.callback(this.parseResults(_8));
61}
62});
63return tf;
64},generateMethod:function(_a,_b,_c){
65return dojo.hitch(this,function(){
66var _d=new dojo.Deferred();
67if((this.strictArgChecks)&&(_b!=null)&&(arguments.length!=_b.length)){
68throw new Error("Invalid number of parameters for remote method.");
69}else{
70this.bind(_a,dojo._toArray(arguments),_d,_c);
71}
72return _d;
73});
74},processSmd:function(_e){
75if(_e.methods){
76dojo.forEach(_e.methods,function(m){
77if(m&&m.name){
78this[m.name]=this.generateMethod(m.name,m.parameters,m.url||m.serviceUrl||m.serviceURL);
79if(!dojo.isFunction(this[m.name])){
80throw new Error("RpcService: Failed to create"+m.name+"()");
81}
82}
83},this);
84}
85this.serviceUrl=_e.serviceUrl||_e.serviceURL;
86this.required=_e.required;
87this.smd=_e;
88}});
89}