root / trunk / web / dojo / dojox / wire / ml / Invocation.js @ 10
History | View | Annotate | Download (2.06 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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 | |||
8 | if(!dojo._hasResource["dojox.wire.ml.Invocation"]){ |
||
9 | dojo._hasResource["dojox.wire.ml.Invocation"]=true; |
||
10 | dojo.provide("dojox.wire.ml.Invocation");
|
||
11 | dojo.require("dojox.wire.ml.Action");
|
||
12 | dojo.declare("dojox.wire.ml.Invocation",dojox.wire.ml.Action,{object:"",method:"",topic:"",parameters:"",result:"",error:"",_run:function(){ |
||
13 | if(this.topic){ |
||
14 | var _1=this._getParameters(arguments); |
||
15 | try{
|
||
16 | dojo.publish(this.topic,_1);
|
||
17 | this.onComplete();
|
||
18 | } |
||
19 | catch(e){
|
||
20 | this.onError(e);
|
||
21 | } |
||
22 | }else{
|
||
23 | if(this.method){ |
||
24 | var _2=(this.object?dojox.wire.ml._getValue(this.object):dojo.global); |
||
25 | if(!_2){
|
||
26 | return;
|
||
27 | } |
||
28 | var _1=this._getParameters(arguments); |
||
29 | var _3=_2[this.method]; |
||
30 | if(!_3){
|
||
31 | _3=_2.callMethod; |
||
32 | if(!_3){
|
||
33 | return;
|
||
34 | } |
||
35 | _1=[this.method,_1];
|
||
36 | } |
||
37 | try{
|
||
38 | var _4=false; |
||
39 | if(_2.getFeatures){
|
||
40 | var _5=_2.getFeatures();
|
||
41 | if((this.method=="fetch"&&_5["dojo.data.api.Read"])||(this.method=="save"&&_5["dojo.data.api.Write"])){ |
||
42 | var _6=_1[0]; |
||
43 | if(!_6.onComplete){
|
||
44 | _6.onComplete=function(){ |
||
45 | }; |
||
46 | } |
||
47 | this.connect(_6,"onComplete","onComplete"); |
||
48 | if(!_6.onError){
|
||
49 | _6.onError=function(){ |
||
50 | }; |
||
51 | } |
||
52 | this.connect(_6,"onError","onError"); |
||
53 | _4=true;
|
||
54 | } |
||
55 | } |
||
56 | var r=_3.apply(_2,_1);
|
||
57 | if(!_4){
|
||
58 | if(r&&(r instanceof dojo.Deferred)){ |
||
59 | var _7=this; |
||
60 | r.addCallbacks(function(_8){
|
||
61 | _7.onComplete(_8); |
||
62 | },function(_9){
|
||
63 | _7.onError(_9); |
||
64 | }); |
||
65 | }else{
|
||
66 | this.onComplete(r);
|
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | catch(e){
|
||
71 | this.onError(e);
|
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | },onComplete:function(_a){ |
||
76 | if(this.result){ |
||
77 | dojox.wire.ml._setValue(this.result,_a);
|
||
78 | } |
||
79 | if(this.error){ |
||
80 | dojox.wire.ml._setValue(this.error,""); |
||
81 | } |
||
82 | },onError:function(_b){ |
||
83 | if(this.error){ |
||
84 | if(_b&&_b.message){
|
||
85 | _b=_b.message; |
||
86 | } |
||
87 | dojox.wire.ml._setValue(this.error,_b);
|
||
88 | } |
||
89 | },_getParameters:function(_c){ |
||
90 | if(!this.parameters){ |
||
91 | return _c;
|
||
92 | } |
||
93 | var _d=[];
|
||
94 | var _e=this.parameters.split(","); |
||
95 | if(_e.length==1){ |
||
96 | var _f=dojox.wire.ml._getValue(dojo.trim(_e[0]),_c); |
||
97 | if(dojo.isArray(_f)){
|
||
98 | _d=_f; |
||
99 | }else{
|
||
100 | _d.push(_f); |
||
101 | } |
||
102 | }else{
|
||
103 | for(var i in _e){ |
||
104 | _d.push(dojox.wire.ml._getValue(dojo.trim(_e[i]),_c)); |
||
105 | } |
||
106 | } |
||
107 | return _d;
|
||
108 | }}); |
||
109 | } |