PDA

View Full Version : Bring HttpProxy to call custom URLs



DrZook
7 Sep 2010, 6:17 AM
Hello together

As the title says, I want a HttpProxy, that is attached to a grid with paging and search field, to store and load data using a custom URL. It's configured like this:

proxy: new Ext.data.HttpProxy({
api: {
read : 'addresses',
create : 'addresses/add',
update: 'addresses/edit',
destroy: 'addresses/delete'
},
doRequest: function(){alert('hallo');}
})Now, the called URL looks like this (requesting page 2 with 25 records on it):

http://test.local/addresses/index?dir=ASC&limit=25&sort=id&start=25But I want the called URL to be this:

http://test.local/addresses/index/start:25/sort:id/direction:asc/limit:25what do I have to do for this?

The background is that I want to use the CakePHP Paginator to fetch data from my DB, which then gets passed to my (paging) ExtJS grid using JSON.

Best
Dr. Zook

Condor
7 Sep 2010, 6:27 AM
The easiest way is probably to call setUrl in the beforeload method.

DrZook
9 Sep 2010, 5:55 AM
Thanks for this Idea. It works now when I attach the listener to a single proxy directly via init config:

var store = new Ext.data.Store({
proxy: new Ext.HttpProxy({
api: {
read : 'addresses/index',
create : 'addresses/add',
update: 'addresses/edit',
destroy: 'addresses/delete'
},
listeners:
{
beforeload:function(proxy,params){
var page = (params.start / params.limit)+1;
var newurl = this.conn.api.read.url;
newurl += '/page:'+page+'/limit:'+params.limit+'/sort:'+params.sort+'/direction:'+params.dir;
this.setUrl(newurl);
},
...
Now, I have many stores in my app who need exactly the same functionality. I wanted to create an own CakephpProxy like this:

Ext.ux.CakeProxy = Ext.extend(Ext.data.HttpProxy, {
initComponent: function(){
Ext.ux.CakeProxy.superclass.initComponent.apply(this);
this.on('beforeload',function(proxy,params){
var page = (params.start / params.limit)+1;
var newurl = this.conn.api.read.url;
newurl += '/page:'+page+'/limit:'+params.limit+'/sort:'+params.sort+'/direction:'+params.dir;
this.setUrl(newurl);
});
}
});

But when I make a new instance of this extended Class, it doesn't work. What's wrong?

proxy: new Ext.ux.CakeProxy({
api: {
read : 'addresses/index',
create : 'addresses/add',
update: 'addresses/edit',
destroy: 'addresses/delete'
}
The Proxy gets up and loads data, but keeps using the false url format.

Condor
9 Sep 2010, 6:42 AM
HttpProxy is not a component, so it doesn't have an initComponent method! You will need to override the constructor instead.