PDA

View Full Version : root param for ext.direct



MichaelOstrovsky
3 May 2010, 4:13 AM
is there a way to define root post-parameter for ext-direct , under which the server requests/responses data will be stacked ? ( just like the 'root' in jsonstore )

I really need it to interchange some top-level info.


UPDATE
Thats what i've done to make it work . Ext support for something similar would be great.



/**
* override for 'root' property request ( ExtDirect provider )
*/
Ext.override(Ext.direct.RemotingProvider,{
doSend: function(data){
var o = {
url: this.url,
callback: this.onData,
scope: this,
ts: data,
timeout: this.timeout
}, callData;

if (Ext.isArray(data)) {
callData = [];
for (var i = 0, len = data.length; i < len; i++) {
callData.push(this.getCallData(data[i]));
}
}
else {
callData = this.getCallData(data);
}

//michael:
//inject response into 'this.root'
if (this.root) {
var tmp = {};
tmp[this.root] = callData;
callData = tmp;
tmp = null;
}
//eof neo.michael


if (this.enableUrlEncode) {
var params = {};
params[Ext.isString(this.enableUrlEncode) ? this.enableUrlEncode : 'data'] = Ext.encode(callData);
o.params = params;
}
else {
o.jsonData = callData;
}
Ext.Ajax.request(o);
}
});

/**
* override for 'root' property response( ExtDirect provider )
*/
Ext.override(Ext.direct.JsonProvider,
{
parseResponse: function(xhr){

//michael: method modified to take in account this.root property in response
var ret={};
if (!Ext.isEmpty(xhr.responseText)) {
if (typeof xhr.responseText == 'object') {
ret = xhr.responseText;
}
else {
ret = Ext.decode(xhr.responseText);
}

if(this.root) return ret[this.root];
return ret;
}
return null;
}
});



usage:



Ext.ns('Direct');
Direct.API = {"url":"...","type":"...","root":"ROOT_PARAM","actions":{...};


ofcourse, back-end support also needed, but thats trivial.