source: [view]
if(this.topic){
var args = this._getParameters(arguments);
try{
dojo.publish(this.topic, args);
this.onComplete();
}catch(e){
this.onError(e);
}
}else if(this.method){
var scope = (this.object ? dojox.wire.ml._getValue(this.object) : dojo.global);
if(!scope){
return; //undefined
}
var args = this._getParameters(arguments);
var func = scope[this.method];
if(!func){
func = scope.callMethod;
if(!func){
return; //undefined
}
args = [this.method, args];
}
try{
var connected = false;
if(scope.getFeatures){
var features = scope.getFeatures();
if((this.method == "fetch" && features["dojo.data.api.Read"]) ||
(this.method == "save" && features["dojo.data.api.Write"])){
var arg = args[0];
if(!arg.onComplete){
arg.onComplete = function(){};
}
//dojo.connect(arg, "onComplete", this, "onComplete");
this.connect(arg, "onComplete", "onComplete");
if(!arg.onError){
arg.onError = function(){};
}
//dojo.connect(arg, "onError", this, "onError");
this.connect(arg, "onError", "onError");
connected = true;
}
}
var r = func.apply(scope, args);
if(!connected){
if(r && (r instanceof dojo.Deferred)){
var self = this;
r.addCallbacks(
function(result){self.onComplete(result);},
function(error){self.onError(error);}
);
}else{
this.onComplete(r);
}
}
}catch(e){
this.onError(e);
}
}