crp_spaeth
5 May 2009, 3:06 AM
Hi there Since i am working on a solution for a generic .net Proxy and Router for the Direct Class I need to know wich changes in Ext.Direct Philosophie are planed.
I dived into the Ext Code again and find it kind of confusing that the batch methode works different than the automatically mechanism.
Since Server-side validation for example can prevent a Record to be saved but it may stops one record to be saved it may saves other records just fine. So there ocurs an error while saving records on the server-side but there a still a few records saved...
So how can the server tell the client wicht record has been saved and wich not?
It would be much easier to have a transaction for every record to save. That would make it possible to return an exception when an error orcur and it would be much easier to rollback the records that failed to save.
Ext.data.Store:
/**
* Send all {@link #getModifiedRecords modifiedRecords} to the server using the
* api's configured save url.
* @param {Object} options
*/
save : function(rs) {
rs = rs || this.getModifiedRecords();
if (!rs.length && !rs instanceof Ext.data.Record && !this.removed.length) {
return false;
}
var action = 'save';
if (this.removed.length) {
try {
this.execute('destroy', this.removed);
}
catch (e) {
throw e; // <-- just re-throw it for now...
}
}
try {
if (Ext.isArray(rs)) {
for (var i = rs.length-1; i >= 0; i--) {
if (rs[i].phantom === true) {
var rec = rs.splice(i, 1).shift();
if (rec.isValid()) {
this.execute('create', rec);
}
}
}
}
else if (rs.phantom) {
if (!rs.isValid()) {
return false;
}
action = 'create';
}
if (Ext.isArray(rs) && rs.length == 1) {
rs = rs[0];
}
if (rs instanceof Ext.data.Record || rs.length > 0) {
this.execute(action, rs);
return true;
}
else {
// no more actions to execute. They may have been spliced-out by create actions above. just return true.
return true;
}
}
catch (e) {
throw e;
}
return true;
},
I would end up with something like this...
/**
* Send all {@link #getModifiedRecords modifiedRecords} to the server using the
* api's configured save url.
* @param {Object} options
*/
save : function(rs) {
rs = rs || this.getModifiedRecords();
if (!rs.length && !rs instanceof Ext.data.Record && !this.removed.length) {
return false;
}
var action = 'save';
if (this.removed.length) {
try {
this.execute('destroy', this.removed);
}
catch (e) {
throw e; // <-- just re-throw it for now...
}
}
try {
if (Ext.isArray(rs)) {
for (var i = rs.length-1; i >= 0; i--) {
var rec = rs.splice(i, 1).shift();
if (rec.phantom === true) {
if (rec.isValid()) {
this.execute('create', rec);
}
} else {
if (rec.isValid()) {
this.execute('save', rec);
}
}
}
}
else if (rs.phantom) {
if (!rs.isValid()) {
return false;
}
action = 'create';
} else {
if (rs.isValid()) {
this.execute('save', rs);
}
}
else {
// no more actions to execute. They may have been spliced-out by create actions above. just return true.
return true;
}
}
catch (e) {
throw e;
}
return true;
},
(falls under the same category like http://extjs.com/forum/showthread.php?p=324928#post324928)
I dived into the Ext Code again and find it kind of confusing that the batch methode works different than the automatically mechanism.
Since Server-side validation for example can prevent a Record to be saved but it may stops one record to be saved it may saves other records just fine. So there ocurs an error while saving records on the server-side but there a still a few records saved...
So how can the server tell the client wicht record has been saved and wich not?
It would be much easier to have a transaction for every record to save. That would make it possible to return an exception when an error orcur and it would be much easier to rollback the records that failed to save.
Ext.data.Store:
/**
* Send all {@link #getModifiedRecords modifiedRecords} to the server using the
* api's configured save url.
* @param {Object} options
*/
save : function(rs) {
rs = rs || this.getModifiedRecords();
if (!rs.length && !rs instanceof Ext.data.Record && !this.removed.length) {
return false;
}
var action = 'save';
if (this.removed.length) {
try {
this.execute('destroy', this.removed);
}
catch (e) {
throw e; // <-- just re-throw it for now...
}
}
try {
if (Ext.isArray(rs)) {
for (var i = rs.length-1; i >= 0; i--) {
if (rs[i].phantom === true) {
var rec = rs.splice(i, 1).shift();
if (rec.isValid()) {
this.execute('create', rec);
}
}
}
}
else if (rs.phantom) {
if (!rs.isValid()) {
return false;
}
action = 'create';
}
if (Ext.isArray(rs) && rs.length == 1) {
rs = rs[0];
}
if (rs instanceof Ext.data.Record || rs.length > 0) {
this.execute(action, rs);
return true;
}
else {
// no more actions to execute. They may have been spliced-out by create actions above. just return true.
return true;
}
}
catch (e) {
throw e;
}
return true;
},
I would end up with something like this...
/**
* Send all {@link #getModifiedRecords modifiedRecords} to the server using the
* api's configured save url.
* @param {Object} options
*/
save : function(rs) {
rs = rs || this.getModifiedRecords();
if (!rs.length && !rs instanceof Ext.data.Record && !this.removed.length) {
return false;
}
var action = 'save';
if (this.removed.length) {
try {
this.execute('destroy', this.removed);
}
catch (e) {
throw e; // <-- just re-throw it for now...
}
}
try {
if (Ext.isArray(rs)) {
for (var i = rs.length-1; i >= 0; i--) {
var rec = rs.splice(i, 1).shift();
if (rec.phantom === true) {
if (rec.isValid()) {
this.execute('create', rec);
}
} else {
if (rec.isValid()) {
this.execute('save', rec);
}
}
}
}
else if (rs.phantom) {
if (!rs.isValid()) {
return false;
}
action = 'create';
} else {
if (rs.isValid()) {
this.execute('save', rs);
}
}
else {
// no more actions to execute. They may have been spliced-out by create actions above. just return true.
return true;
}
}
catch (e) {
throw e;
}
return true;
},
(falls under the same category like http://extjs.com/forum/showthread.php?p=324928#post324928)