PDA

View Full Version : [3.1] Direct Store with API, Update action takes no parameters



migolo
23 Jan 2010, 10:14 PM
Hi again.

I configured a Direct Store with API actions, in Ext 3.0 everything was working perfectly, when I upgraded to 3.1, the "update" action isn't sending the parameters:

Here is the Request payload with version 3.1:


{"action":"Productos","method":"modificar","data":[],"type":"rpc","tid":11}And the response:


{"type":"exception","tid":11,"message":"Not enough required params specified for method: modificar on class Productos"}In version 3.0.0 the Request payload is:


{"action":"Productos","method":"modificar","data":["3","{\"id\":\"3\",\"nombre\":\"Tangram 1, aktuell Lektion 5-8\",\"precio\":481,\"cantidad\":\"5\"}"],"type":"rpc","tid":10}

And the response is:

{"type":"rpc","tid":10,"action":"Productos","method":"modificar","result":{"id":"3","nombre":"Tangram 1, aktuell Lektion 5-8","precio":481,"cantidad":5}}


I am using the same application only testing with the newer version, this is how I configured the store and was working in version 3.0.0 and isn't in 3.1


var productos_writer = new Ext.data.JsonWriter({
writeAllFields: true // write all fields, not just those that changed
});

Productos = new Ext.data.DirectStore({
api: {
read: Migolo.Productos.listar,
update: Migolo.Productos.modificar
},
paramOrder: ['buscar','start'],
baseParams: {
buscar: ""
},
autoLoad: true,
root: "data",
reader: new Ext.data.JsonReader({
totalProperty: 'totalCount',
idProperty: 'id',
root: 'data'
}, [{
name: 'id',
mapping: 'id'
},{
name: 'nombre',
mapping: 'nombre'
},{
name: 'precio',
mapping: 'precio'
},{
name: 'cantidad',
mapping: 'cantidad'
}]),
writer: productos_writer
});


I must say that the "read" action is working in both versions sending the right params.

Best regards, and sorry for my English.

Miguel González

vinnybozz
25 Jan 2010, 6:44 AM
Hi Miguel, I am also experiencing the same issue.

The 'update' action is firing but with empty data (It was working in 3.0.3).

I do not know why however...

vinnybozz
25 Jan 2010, 7:23 AM
I tracked down the problem and it seems to occur in the save method of the Ext.data.Store class definition (around line 20125):


len = queue.length;
if(len){
batch = ++this.batchCounter;
for(var i = 0; i < len; ++i){
trans = queue;
[I]console.debug(trans); // #### ADDED THIS
data[trans[0]] = trans[1];
}
console.debug(data); // #### ADDED THIS
if(this.fireEvent('beforesave', this, data) !== false){
for(var i = 0; i < len; ++i){
trans = queue[i];
this.doTransaction(trans[0], trans[1], batch);
}
return batch;
}
}

When testing within my own program:
trans contains the following array:

["update", [Object { id="3855", more...}]]
However, it seems like data[trans[0]] = trans[1]; is not working since when I output data, I get the following:
Object { update=}
As if trans[1] was empty

Condor
25 Jan 2010, 7:39 AM
When testing within my own program:
trans contains the following array:

["update", [Object { id="3855", more...}]]
However, it seems like data[trans[0]] = trans[1]; is not working since when I output data, I get the following:
Object { update=}
As if trans[1] was empty

That's just a display error in Firebug.

Try using:

console.dir(data);

vinnybozz
25 Jan 2010, 7:52 AM
Hi Condor, you're right, the data object now seems to contain the correct information.

The data is still not being sent though, I'll keep trying to find something (using console.dir now !! )

cerad
25 Jan 2010, 10:24 AM
This works in 3.1.x:


var writer = new Ext.data.JsonWriter
({
encode: false, // Very important, defaults to true
writeAllFields : true
});
var reader = new Ext.data.JsonReader
({
root : 'records',
idProperty : 'event_person_id',
totalProperty : 'totalCount',
successProperty : 'success',
messageProperty : 'message',

fields : recordFields
});
var proxy = new Ext.data.DirectProxy
({
api :
{
read: Zayso.Direct.Event_EventPerson.read,
create: Zayso.Direct.Event_EventPerson.create,
update: Zayso.Direct.Event_EventPerson.update
},
paramsAsHash: true
});
var gridStore = new Ext.data.DirectStore
({
// These all come from Store
storeId : 'referee-signup-grid-store',
baseParams : { event_id : this.eventId, base2: 'somthing' },
autoLoad : false,
autoSave : false,

remoteSort : false,
sortInfo : { field : 'position_id', direction : 'ASC'},

writer : writer,
reader : reader,
proxy : proxy
});


Try setting encode to false.

And I always use paramsAsHash which ends up sending all the parameters in one array. The direct functions use a len of 1.

migolo
25 Jan 2010, 12:47 PM
Hi again,

Cerad, compring your code, I changed the writer to do an encode: false, and yes, it sends the data, so i think there is a problem with the encode function because I tried setting it to true and the update function sent empty data.

cerad
25 Jan 2010, 7:14 PM
Unless you have a burning desire to encode the data then just leave it false.

migolo
25 Jan 2010, 7:35 PM
I can manage that, a thing I didn't saw before is that the request is sent in a different way:

I get this:

{"action":"Productos","method":"modificar","data":[{"buscar":"","data":{"id":"3","nombre":"Tangram 1, aktuell Lektion 5-8","precio":480,"cantidad":"5"}}],"type":"rpc","tid":10}Instead of this:

{"action":"Productos","method":"modificar","data":["3","{\"id\":\"3\",\"nombre\":\"Tangram 1, aktuell Lektion 5-8\",\"precio\":480,\"cantidad\":\"5\"}"]
,"type":"rpc","tid":10}I only added the encode: false