Connection.js
Ext.data.Connection = function(config){
Ext.apply(this, config);
this.events = {
'beforerequest' : true,
'requestcomplete' : true,
'requestexception' : true
};
};
Ext.extend(Ext.data.Connection, Ext.util.Observable, {
timeout : 30000,
request : function(options){
if(this.fireEvent('beforerequest', this, options) !== false){
var p = options.params;
if(typeof p == 'object'){
p = Ext.urlEncode(Ext.apply(options.params, this.extraParams));
}
var cb = {
success: this.handleResponse,
failure: this.handleFailure,
scope: this,
argument: {options: options},
timeout : this.timeout
};
var method = options.method||this.method||(p ? 'POST' : 'GET');
if(this.autoAbort !== false){
this.abort();
}
this.transId = YAHOO.util.Connect.asyncRequest(method, options.url || this.url, cb, p);
}else{
if(typeof options.callback == 'function'){
options.callback.call(options.scope||window, options, null, null);
}
}
},
isLoading : function(){
return this.transId ? true : false;
},
abort : function(){
if(this.isLoading()){
YAHOO.util.Connect.abort(this.transId);
}
},
handleResponse : function(response){
this.transId = false;
var options = response.argument.options;
this.fireEvent('requestcomplete', this, response, options);
if(typeof options.callback == 'function'){
options.callback.call(options.scope||window, options, true, response);
}
},
handleFailure : function(response, e){
this.transId = false;
var options = response.argument.options;
this.fireEvent('requestexception', this, response, options, e);
if(typeof options.callback == 'function'){
options.callback.call(options.scope||window, options, false, response);
}
}
});
yui-ext - Copyright © 2006 Jack Slocum. |
Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.