PDA

View Full Version : How detect that server CRUD operations have been successful?



simonr26
17 Dec 2011, 10:45 AM
Hello,
How can I determine if Create, Update, Delete operations
complete successfully? I need to indicate to the user
if a server CRUD operation fails.


I have created store as below.
There are 3 event handlers for the 3 operations - each makes
changes to the store and performs a sync.
The controller actions are correctly invoked, and I return
similar to the following:
{"success": true,"dests": {"id":456,"res":10508,"descr":"updated"}}


I can determine success of a read by using the store.load callback
function in conjunction with the successProperty config.
It may be possible to determine if successful updates/edits using the
successProperty, since if response returns false, a dirty record
seems to be shown?
The successProperty doesn't seem to be relevant to create/delete
operations.




onAdd: function (btn) {
var gridId = Ext.getCmp('gridpanelid');
gridId.store.add(new APP.model.ModelClass);
gridId.store.sync();
},
onEdit: function (btn) {
var gridId = Ext.getCmp('gridpanelid');
var sel = gridId.getSelectionModel().getSelection()[0];
sel.set('descr', 'updated');
gridId.store.sync();
},
onDel: function (btn) {
var gridId = Ext.getCmp('gridpanelid');
var sel = gridId.getSelectionModel().getSelection()[0];
gridId.store.remove(s);
gridId.store.sync();
}


var newWriter = Ext.create('Ext.data.writer.Json',{
})


Ext.define('APP.store.TheStores', {
extend: 'Ext.data.Store',
model: 'APP.model.ModelClass',
proxy: {
type: 'ajax',
api: {
create: 'dest/create',
read: 'dest/list',
update: 'dest/update',
destroy:'dest/destroy'
},
reader: {
type: 'json',
successProperty: 'success'
},
writer: newWriter
}
}),...


kind regards,
Simon

mitchellsimoens
18 Dec 2011, 4:23 AM
When does the write event happen?

simonr26
18 Dec 2011, 5:08 AM
Hello,

thank you for your reply.
Following the add,set,remove methods, the store is updated.
The sync() method then causes the writer to post the altered data
to the server using the url.
However I do not know how the client can determine if the server
successfully updated the database. e.g. is there a way ext js 4 can
interpret any response?

kind regards,
Simon