Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions Ext.ux.OfflineSyncStore-min-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,49 @@ Ext.define('Ext.ux.OfflineSyncStore', {
* @private
* @returns {void}
*/
onBatchComplete: function(batch) {
onBatchComplete : function(batch) {
this.callParent(arguments);
if (this.isLocalMode()) {
this.fireEvent('localsynccomplete', this, batch);
if (this.doAutoServerSync()) {
this.syncServer();
}
} else {
this.resetPhantomForCreatedRecords(batch);
this.fireEvent('remotesynccomplete', this, batch);
}
},

/**
* This is called once the batch operation failed.
* We do nothign special here, we just fire event to notify exception.
* @method
* @private
* @returns {void}
*/
onBatchException: function(batch, operation) {
onBatchException : function(batch, operation) {
this.callParent(arguments);
var event = 'remotesyncexception';
if (this.isLocalMode()) {
event = 'localsyncexception';
this.fireEvent('localsyncexception', this, batch, operation);
} else {
this.resetPhantomForCreatedRecords(batch);
this.fireEvent('remotesyncexception', this, batch, operation);
}
this.fireEvent(event, this, batch, operation);
},

/**
* This method is used to reset phantom for created records once the batch is completed
* @private
* @returns {void}
*/
resetPhantomForCreatedRecords : function(batch) {
Ext.each(batch.operations, function(operation) {
if (operation.getAction() === "create") {
Ext.each(operation.getRecords(), function(record) {
record.phantom = false;
}, this);
}
}, this);
},

/**
Expand Down Expand Up @@ -187,7 +204,13 @@ Ext.define('Ext.ux.OfflineSyncStore', {
// This is required so the store can map up the returned records to the ones in the store to update IDs etc.
// When we do a local save a new ID gets generated for the record which we don't want to send to the server.
for(var i = 0; i < toCreate.length; i++){
toCreate[i].data[this.getModel().getIdProperty()] = toCreate[i].id;
var record = toCreate[i];
record.data[this.getModel().getIdProperty()] = record.id;

// Once a new record has been saved to local db, the phantom property is set to false.
// As a consequence when we sync with server the phantom property is still false and the POST url has the id in the path (ie POST /model/ext-record-123) and this is wrong.
// Therefore we force phantom to be true (phantom is set back to false in "resetPhantomForCreatedRecords")
record.phantom = true;
}

operations.create = toCreate;
Expand Down
2 changes: 1 addition & 1 deletion Ext.ux.OfflineSyncStore-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 30 additions & 7 deletions Ext.ux.OfflineSyncStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,49 @@ Ext.define('Ext.ux.OfflineSyncStore', {
* @private
* @returns {void}
*/
onBatchComplete: function(batch) {
onBatchComplete : function(batch) {
this.callParent(arguments);
if (this.isLocalMode()) {
this.fireEvent('localsynccomplete', this, batch);
if (this.doAutoServerSync()) {
this.syncServer();
}
} else {
this.resetPhantomForCreatedRecords(batch);
this.fireEvent('remotesynccomplete', this, batch);
}
},

/**
* This is called once the batch operation failed.
* We do nothign special here, we just fire event to notify exception.
* @method
* @private
* @returns {void}
*/
onBatchException: function(batch, operation) {
onBatchException : function(batch, operation) {
this.callParent(arguments);
var event = 'remotesyncexception';
if (this.isLocalMode()) {
event = 'localsyncexception';
this.fireEvent('localsyncexception', this, batch, operation);
} else {
this.resetPhantomForCreatedRecords(batch);
this.fireEvent('remotesyncexception', this, batch, operation);
}
this.fireEvent(event, this, batch, operation);
},

/**
* This method is used to reset phantom for created records once the batch is completed
* @private
* @returns {void}
*/
resetPhantomForCreatedRecords : function(batch) {
Ext.each(batch.operations, function(operation) {
if (operation.getAction() === "create") {
Ext.each(operation.getRecords(), function(record) {
record.phantom = false;
}, this);
}
}, this);
},

/**
Expand Down Expand Up @@ -184,7 +201,13 @@ Ext.define('Ext.ux.OfflineSyncStore', {
// This is required so the store can map up the returned records to the ones in the store to update IDs etc.
// When we do a local save a new ID gets generated for the record which we don't want to send to the server.
for(var i = 0; i < toCreate.length; i++){
toCreate[i].data[this.getModel().getIdProperty()] = toCreate[i].id;
var record = toCreate[i];
record.data[this.getModel().getIdProperty()] = record.id;

// Once a new record has been saved to local db, the phantom property is set to false.
// As a consequence when we sync with server the phantom property is still false and the POST url has the id in the path (ie POST /model/ext-record-123) and this is wrong.
// Therefore we force phantom to be true (phantom is set back to false in "resetPhantomForCreatedRecords")
record.phantom = true;
}

operations.create = toCreate;
Expand Down