PDA

View Full Version : CRUD Store Sync response



Jangla
19 Jun 2013, 5:38 AM
I have a store that's set to auto sync and I have to turn if off so I can define a callback after sync completes.

How can I get the response json of the server in the same way I would if I'd manually crafted an Ext.Ajax.request?

Right now it doesn't look like it's possible.




store.suspendAutoSync()
myRecord.beginEdit();
curRecord.set( {
status : 'somStatus',
statusLabel : 'Published'
} );
myRecord.endEdit( true );
store.sync( {
callback : this.afterPreviewUpdate,
scope : this
} )





From that, afterPreviewUpdate won't be given the json response in the same way an ajax request would be so I could decode the responseText and act upon it.

Edit; More detail on the use case may help. I have a DataView being driven from this store. When a user clicks to delete an item from this DataView, the delete call is made by the CRUD api but the server may reject the request (for a number of reasons). The server returns what I would expect in a json response and if the delete request is rejected I need to return the store (and therefore the DataView) to it's previous state. But I seem to be unable to capture that response successfully in Ext.

Jangla
20 Jun 2013, 1:17 AM
Found a solution in case anyone else comes up against this:





Ext.define( 'myCrudStore', {
extend : 'Ext.data.JsonStore',
config : {
autoLoad : false,
autoSync : true,
remoteSort : false,
proxy : {}
},


constructor : function( cfg ){


var me = this;


me.initConfig( cfg );
me.callParent( arguments );
me.proxy.on( 'exception', me.onProxyException, me );


},


onProxyException : function( proxy, response, operation, eOpts ){
this.rejectChanges();
}
} )


Ext.create( 'myCrudStore', {
storeId : 'myStoreId',
model : 'myModel',
proxy : {
type : 'myProxy',
api : {
read : '/url/to/read.json',
create : '/url/to/create.json',
update : '/url/to/update.json',
destroy : '/url/to/destroy.json',
}
}
} );


Of course if anyone has any refinements on the above, please feel free to chip in :D