Fabricio,
Thanks again for looking into this issue. The problem is that when multiple operations are being performed, only the first one will be processed but the second and third (if any) will not. For example, assuming the process order is create,update,destroy and all operations return success. When the user makes changes to the records in the grid which cause all 3 operations to be required:
- The first call to store.sync() will cause the new records to be sent to the code-behind, then the unhandled exception will occur which prevents the update and delete operations from being performed.
- Calling store.sync() again will cause the updated records to be sent and then the exception will occur.
- Calling store.sync() a third time will cause the deleted records to be sent.
The exception seems to be caused by the way the temporary proxy is being destroyed. The temporary proxy is needed until all 3 (potential) operations are completed, but it is destroyed after the first operation when endprocessresponse happens. I've tried the following fix which seems to correct the problem (the only change is the if statement in the endprocessresponse handler):
Ext.data.AbstractStore.override({
createTempProxy: function (callback, proxyConfig, sync) {
var oldProxy = this.proxy,
proxyId = Ext.id(),
proxy = this.serverProxy ? Ext.createByAlias('proxy.' + this.serverProxy.type, Ext.apply({
model: this.model,
reader: {
type: oldProxy && oldProxy.reader && oldProxy.reader.type ? oldProxy.reader.type : "json",
rootProperty: oldProxy && oldProxy.reader ? "data." + oldProxy.reader.getRootProperty() : "data"
},
writer: oldProxy.writer
}, proxyConfig || {}, this.serverProxy)) : Ext.createByAlias('proxy.page', Ext.applyIf({
type: 'page',
model: this.model,
reader: {
type: oldProxy && oldProxy.reader && oldProxy.reader.type ? oldProxy.reader.type : "json",
rootProperty: oldProxy && oldProxy.reader ? "data." + oldProxy.reader.getRootProperty() : "data"
},
writer: oldProxy.writer
}, proxyConfig || {})),
scope;
this.proxy = proxy;
this[proxyId] = proxy;
this._oldProxy = oldProxy;
this.proxy.on("exception", this.onProxyException, this);
this.proxy.on("beforerequest", this.buildRequestParams, this);
this.proxy.on("beforerequest", function () {
this.proxy = oldProxy;
}, this, { single: true });
scope = {
proxyId: proxyId,
callback: callback,
proxy: this.proxy,
oldProxy: oldProxy,
store: this
};
if (callback) {
if (sync) {
this.proxy.onBatchComplete = Ext.Function.createInterceptor(
this.proxy.onBatchComplete,
function (batchOptions, batch) {
this.callback.call(this, null, !batch.hasException);
},
scope
);
}
else {
this.proxy.on(
"afterrequest",
function (proxy, request, success) {
this.callback.call(this, request, success);
},
scope);
}
}
this.proxy.on(
"endprocessresponse",
function (proxy, response, operation) {
if (!this.store.isSyncing) { // add this check to be sure the operations are all complete
this.proxy.destroy();
this.proxy.clearListeners();
delete this.store[this.proxyId];
delete this.store._oldProxy;
}
},
scope
);
}
});
I've tested this with version 3.3 and the 4.0 examples and it seems to solve the problem.