PDA

View Full Version : CRUD and Form Submit Documentation



Dumas
10 Mar 2010, 4:58 AM
Hi!

I have searched the forum but couldn't find something and it gets hard to allway check how the response look like in firebug..
Is there somewhere a definition of how the standard crud for stores (with and without baseParams) and the stdard load & submit looks like?

thx
Dumas

Stju
11 Mar 2010, 9:06 PM
As of 3.2 there are some breaking changes from previous version regarding responses from server. Now they are consistent with same pattern, but requires that success property be submitted with each call.
Hopefully this will save some braincells B)
@Dumas Store must have an 'api' section and some other to work correctly with extra params - see code, it's self explanatory:


...
api: {
read: myDirectClass.readData,
create: myDirectClass.createData,
update: myDirectClass.updateData,
destroy: myDirectClass.removeData
},
paramOrder: ['sort','dir','start','limit','fields','query'],
paramsNames: { start : 'start', limit : 'limit', sort : 'sort', dir : 'dir', fields : 'fields', query : 'query'},
baseParams: {start : 0, limit : 20, sort : 'field_to_use_for_sorting', dir : 'ASC', fields:'', query:''},
root: 'data',
idProperty: 'id',
totalProperty: 'total',
successProperty: 'success',
paramsAsHash: false,
writer:new Ext.data.JsonWriter({ encode: false}), // Important to have all CRUD actions!
autoLoad : true,
autoSave: true, // <- IMPORTANT to send data automatically to server!
batchSave: false,
...
Base responses must be EXACTLY like this, but You can of course add own fields..
As sample PHP:


//read:
return array(
'success'=>$status,
'total'=>(int)$total_rows['total'],
'data'=>$all_rows
);

//create:
$response_rows = array();
$response_rows['id']=$insert_id;

$result=array();
$result['success'] = true;
$result['data']=$response_rows;
return $result;

//update:
$result=array();
$result['success'] = true;
$result['data']=$response_rows;
return $result;

//destroy:
$result=array();
$result['success'] = true;
$result['data']=array();
return $result;

All responses must be JSON!
Remaining information can be found in documentation.
Stju

Stju
11 Mar 2010, 9:09 PM
To make a call where baseParams are involved should look like this:


reloadPublications:function(){
this.yourDirectStore.setBaseParam('menu_id', this.menuId);
this.yourDirectStore.load();
},

Dumas
13 Mar 2010, 7:38 PM
Hi!

I'm already successfully using Ext.Direct, but sometimes Exts reactions are a bit surprising. I'm using ExtJS 3.1, and so the query and the expected response is sometimes unclear. E.g. how the the queries change when I add base params, and so on.

So I thought maybe there is something already written...
I would like to have a table like this: http://img139.imageshack.us/img139/3239/screencapturelo.png
(This is neither complete nor 100% accurate)

thx
Dumas