PDA

View Full Version : [FIXED][3.0rc1.1] Ext.data.HttpProxy - POST Method does not work



kirill533
6 May 2009, 7:39 AM
I create

Ext.data.HttpProxy({
method: 'POST'
});

and put it to Ext.data.GroupingStore config.

But grid loads with GET method.

Sorry for my English.

lophyte
6 May 2009, 7:40 AM
Can you paste a bit more of your code? I'd like to see how you're passing the HttpProxy to your Store, and your Store to your Grid.

kirill533
6 May 2009, 7:52 AM
Master.tools.grid = Ext.extend(Ext.grid.EditorGridPanel, {

constructor: function(config) {

...

getRequestConfig: function (config) {

var js = config.js || false;

var failureMode = config.failureMode ? true : false;
config = config || {};

config.method = config.method || 'POST';

var checkResult = this.checkResult;
var success = config.success || function(){};

config.success = function(response) {
var result;
if (js) {
try {
result = Master.Json.decodeResponse(response, js);

if (!result.hasOwnProperty('success')) {
return;
}
} catch (err) {
Master.Error.handleException(err, 'Ошибка при обработке резальтата запроса');
}
} else {
result = Master.Json.decodeResponse(response);
}
if (!failureMode) {
checkResult(result);
}
success(response);
};

config.headers = config.headers || {};

config.headers.master_req_type = 'master_json';

var failure = config.failure || function(){};

config.failure = function(response) {
try {

var result = Master.Json.decodeResponse(response);
checkResult(result, js);

failure(response);

} catch (err) {
Master.Error.handleException(err, 'Не удалось установить соединение с сервером', '<?= $this->translate('Не удалось установить соединение с сервером')?>');
}
};

return config;
};

getListProxy = function(){
var c = getRequestConfig({
url: '/proxy/entity/list'
});

return new Ext.data.HttpProxy(c);
};

initDataStore = function(modelConfig) {

modelConfig.order = modelConfig.order || {};

modelConfig.order.field = modelConfig.order.field || 'name';
modelConfig.order.type = modelConfig.order.type || 'ASC';

var gSConfig = {
id: key + '_grid',
proxy: getListProxy(),
baseParams:{key: key, is_table: isTable ? 1 : 0},
reader: new Ext.data.JsonReader({"root":"data","totalProperty":"total","id":"id"}, modelConfig.map),
sortInfo:{field: modelConfig.order.field, direction: modelConfig.order.type},
remoteGroup: true,
remoteSort: true
};

if (config.groupField) {
gSConfig.groupField = config.groupField;
defaultParams.groupBy = config.groupField;
}

DataStore = new Ext.data.GroupingStore(gSConfig);
};

...

initDataStore();

...

var defConfig = {
plugins: plugins,
store: DataStore,
autoSizeColumns: true,
cm: ColumnModel,
enableColLock:false,
loadMask: {msg:"Загрузка...", disabled:false},
stripeRows: true,
bbar: bbar || null,
title: config.modelConfig.title || null,
clicksToEdit: 2,
selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
tbar: new Ext.Toolbar({items:tbar}),
view: new ViewObject({
enableGrouping: mode !== 'simple',
enableGroupingMenu: mode !== 'simple',
emptyText: '<h1><?= $this->translate('No Record found') ?></h1>',
defaultEmptyText: '<h3><?= $this->translate('No Record found') ?></h3>',
forceFit:true
})
};

var i;
for (i in defConfig) { if (defConfig.hasOwnProperty(i)) {
config[i] = config[i] || defConfig[i];
}}

this.addEvents('changessaved');

Master.tools.grid.superclass.constructor.apply(this, arguments);

}
...
});

lophyte
6 May 2009, 8:06 AM
You've got DataStore = new Ext.... in your initDataStore() function, but later when you're building your grid, you have "store: DataStore".

I think, but I'm not 100% sure, that when you define DataStore in your function, its being declared in the functions local scope, and not accessible outside of the function. What if you declared it as this.DataStore, and in your grid, you had store: this.DataStore?

kirill533
6 May 2009, 8:13 AM
You've got DataStore = new Ext.... in your initDataStore() function, but later when you're building your grid, you have "store: DataStore".

I think, but I'm not 100% sure, that when you define DataStore in your function, its being declared in the functions local scope, and not accessible outside of the function. What if you declared it as this.DataStore, and in your grid, you had store: this.DataStore?

It is a very simplified version. This error occurs only if I use RC1.1 version. RC 1.0 works correctly with my code.

kirill533
6 May 2009, 8:29 AM
This code does not depend of my options with method POST



Ext.extend(Ext.data.HttpProxy, Ext.data.DataProxy, {
...
doRequest:function(action,rs,params,reader,cb,scope,arg){
varo={
params:params||{},
method:(action===Ext.data.Api.READ)?"GET":"POST",
request:{
callback:cb,
scope:scope,
arg:arg
},
reader:reader,
callback:this.createCallback(action,rs),
scope:this
};
if(this.useAjax){
//Settheconnectionurl.Ifthis.conn.urlisnotnullhere,
//theusermayhaveoverriddentheurlduringabeforeactionevent-handler.
//this.conn.urlisnullifiedaftereachrequest.
if(this.conn.url===null){
this.conn.url=this.buildUrl(action,rs);
}
elseif(this.prettyUrls===true&&rsinstanceofExt.data.Record&&!rs.phantom){
this.conn.url+='/'+rs.id;
}

Ext.applyIf(o,this.conn);

//Ifacurrentlyrunningrequestisfoundforthisaction,abortit.
if(this.activeRequest[action]){
Ext.Ajax.abort(this.activeRequest[action]);
}
this.activeRequest[action]=Ext.Ajax.request(o);

//requestissent,nullifytheconnectionurlinpreparationforthenextrequest
this.conn.url=null;

}else{
this.conn.request(o);
}
},
...

evant
6 May 2009, 9:19 AM
The code for this is different in SVN, it appears to have been fixed already:



doRequest : function(action, rs, params, reader, cb, scope, arg) {
var method = (this.api[action]) ? this.api[action]['method'] : undefined;
var o = {
params : params || {},
method: method,
request: {
callback : cb,
scope : scope,
arg : arg
},
reader: reader,
callback : this.createCallback(action, rs),
scope: this
};
//.......
}

kirill533
6 May 2009, 9:43 AM
I see. But I'm not sure that new code will be compatible. Please, check it.
Maybe it must be


if (this.method) {
var method = this.method;
} else {
var method = (this.api[action]) ? this.api[action]['method'] : undefined;
}

or something else

stillema
7 May 2009, 7:36 AM
I'm having a problem with this code also, but isn't the fundamental problem this line?


Ext.applyIf(o, this.conn);

Because if I have defiend "this.conn" with different properties (e.g., method: 'POST'), it is being ignored at this point. I've changed this with my own override and it is working for me.

kirill533
7 May 2009, 11:29 AM
With function Ext.apply() it's working for me too.

christocracy
7 May 2009, 4:10 PM
Evan's right, this code is fixed in SVN


The code for this is different in SVN, it appears to have been fixed already:


Also:


Because if I have defiend "this.conn" with different properties (e.g., method: 'POST'), it is being ignored at this point. I've changed this with my own override and it is working for me.


In SVN code, method should not be ignored anymore. I just tried here and it works.

You should all be aware of new way of defining Proxy api as well where you can optionally define the method for each action. I doubt this is in RC1.1.


proxy = new Ext.data.HttpProxy({
prettyUrls: true,
api: {
load: {url: '/users/load', method: 'GET'},
create: '/users/create',
save: '/users/update',
destroy: '/users/destroy'
}
});

MD
7 May 2009, 9:15 PM
Sorry, just to clarify -- this has been fixed in SVN post-RC1.1?

Just wanted to make sure, as I just noticed the HttpProxy.js included with RC1.1 was an old 3.0 Pre-alpha, older than what was included with RC1. :-?

MD

stillema
8 May 2009, 7:52 AM
Evan's right, this code is fixed in SVN


I'm not seeing anything in SVN, and I should be up to date with the latest revision -- I just did another 'svn update' this morning. So I'm not seeing the code that Evan posted.



You should all be aware of new way of defining Proxy api as well where you can optionally define the method for each action. I doubt this is in RC1.1.


proxy = new Ext.data.HttpProxy({
prettyUrls: true,
api: {
load: {url: '/users/load', method: 'GET'},
create: '/users/create',
save: '/users/update',
destroy: '/users/destroy'
}
});



I was not aware of this new way -- is it documented somewhere? This doesn't work for me either (as you appear to say you doubted). It looks like the Connection class doesn't recognize 'load' as an object.

christocracy
10 May 2009, 9:23 AM
This code was committed as revision 3870 on May 1.



var method = (this.api[action]) ? this.api[action]['method'] : undefined;
var o = {
params : params || {},
method: method,
request: {
callback : cb,
scope : scope,
arg : arg
},
reader: reader,
callback : this.createCallback(action, rs),
scope: this
};
.
.
.

stillema
11 May 2009, 7:11 AM
Ok, I've managed to update my source code to the correct revision. After using the "api" options as you noted, I have my code working with no override/patching required.

Thanks for you help Chris!

Scott

christocracy
11 May 2009, 10:44 AM
After using the "api" options as you noted, I have my code working with no override/patching required..

Awesome, good to hear.