PDA

View Full Version : Store sync callback



xjpmauricio
6 Oct 2011, 8:26 AM
Hi, how can i get the callback of a store sync() ?

Something like:



scope.storeDocuments.sync({
success: function() {

},
failure: function() {

}
});



Can it be done without setting the "afterRequest" event on the store itself?

Can it be done without overriding anything?

gevik
6 Oct 2011, 12:07 PM
unfortunately the functionality does not exist yet. I have placed a feature request for this. now let's see what the dev team decides...

gevik
7 Oct 2011, 2:06 AM
BTW. take a look at this post, perhaps it helps.
http://www.sencha.com/forum/showthread.php?149924-Store.sync()-method-with-options (http://www.sencha.com/forum/showthread.php?149924-Store.sync%28%29-method-with-options).

xjpmauricio
7 Oct 2011, 2:17 AM
Thanks a lot Gevik, i picked up your code and converted to this:

Ext.override(Ext.data.Store, {
sync: function(config) {
var me = this;
me.is_sync_opr = true;
var callback_handler = function() {
if (me.is_sync_opr === true && config.callback && Ext.isFunction(config.callback)) {
config.callback.apply(this, arguments);
}
me.sync_events = false;
};
var update_handler = function(store, record, opr) {
if (me.is_sync_opr === true && config[opr] && Ext.isFunction(config[opr])) {
config[opr].apply(this, [record, opr]);
}
}
var exception_handler = function(proxy, response, opr) {
if (me.is_sync_opr === true) {
if (opr && opr.records && Ext.isFunction(config.reject)) {
Ext.each(opr.records,
function(r) {
config.reject.apply(me, [r, opr]);
});
}
}
me.is_sync_opr = false;
}
if (me.sync_events == undefined) {
me.model.proxy.addListener('exception', exception_handler, this);
me.addListener('write', callback_handler, this);
me.addListener('update', update_handler, this);
me.sync_events = true;
}
this.callParent();
}
});