azinyama
4 Sep 2012, 12:31 PM
Hi all!!!
I'm using Ext.Direct Router to load/create/update/delete records. Code below:
Ext.define('ClaimCatch_RIS.store.Procedure',
{
extend : 'Ext.data.Store',
id : 'Procedures',
autoLoad : false,
autoSave : false,
autoSync : true,
remoteSort : true,
model : 'ClaimCatch_RIS.model.Procedure',
proxy : {
type : 'direct',
reader : {
type : 'json',
successProperty : 'success',
messageProperty : 'message',
totalProperty : 'total',
root : 'data',
idProperty : 'Procedure_RowID'
},
writer : {
type : 'json',
encode : false,
writeAllFields : true
},
api : {
create : _ProcedureHandler.Create_Procedure,
read : _ProcedureHandler.Load_Procedure,
update : _ProcedureHandler.Update_Procedure,
destroy : _ProcedureHandler.Delete_Procedure
},
listeners : {
exception : function(proxy, response, operation)
{
Ext.MessageBox.show(
{
title : 'Remote Exception: Procedure',
msg : operation.getError(),
icon : Ext.MessageBox.ERROR,
buttons : Ext.Msg.OK
});
}
},
afterRequest: function (request, success)
{
if (request.action == 'read')
{
this.readCallback(request, success);
}
else if (request.action == 'create')
{
this.createCallback(request, success);
}
else if (request.action == 'update')
{
this.updateCallback(request, success);
}
else if (request.action == 'destroy')
{
this.deleteCallback(request, success);
}
},
readCallback: function (request, success)
{
if (!request.operation.success)
{
Ext.Msg.show(
{
title : 'Procedure Load Error',
msg : request.operation.getError(),
buttons : Ext.Msg.OK,
icon : Ext.Msg.WARNING
});
}
},
createCallback: function (request, success)
{
if (!request.operation.success && request.operation.hasException())
{
Ext.Msg.show(
{
title : 'Procedure Create Error',
msg : request.operation.getError(),
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
// else
// {
// request.records[0].phantom = true;
// }
},
updateCallback: function (request, success)
{
if (!request.operation.success && request.operation.hasException())
{
console.log(request.records[0]);
request.records[0].rejectChanges();
Ext.Msg.show(
{
title : 'Procedure Update Error',
msg : request.operation.getError(),
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
},
deleteCallback: function (request, success)
{
if (!request.operation.success && request.operation.hasException())
{
Ext.Msg.show(
{
title : 'Procedure Delete Error',
msg : request.operation.getError(),
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
},
scope : this
}
});
It works fine, but my 'problem' comes when I try to add a new row to the grid. I wanted to add a row with out actually calling the create direct method. Is this possible. Below my controller all function:
onAdd : function(btn)
{
var isBlank = false;
this.getProcedureStore().each(function (record)
{
if (record.data['Procedure_RowID'] == 0)
{
Ext.Msg.show(
{
title : 'Warning',
msg : 'Please update the blank procedure first.',
buttons : Ext.Msg.OK,
icon : Ext.Msg.WARNING
});
if (null == record.index)
{
record.index = 0;
}
isBlank = true
this.getProcedureWindow().plugins[0].startEdit(record.index, 1);
return false;
}
}, this);
if (!isBlank)
{
this.getProcedureStore().insert(0, new this.getProcedureModel());
this.getProcedureWindow().plugins[0].startEdit(0, 1);
}
},
Second question is. Once a new record has been saved to the database and the record is returned. How do I update the store. I'm using Procedure_RowID as my key which is sent back by the database and I want it to be update/set in the store for the saved record.
I'm using Ext.Direct Router to load/create/update/delete records. Code below:
Ext.define('ClaimCatch_RIS.store.Procedure',
{
extend : 'Ext.data.Store',
id : 'Procedures',
autoLoad : false,
autoSave : false,
autoSync : true,
remoteSort : true,
model : 'ClaimCatch_RIS.model.Procedure',
proxy : {
type : 'direct',
reader : {
type : 'json',
successProperty : 'success',
messageProperty : 'message',
totalProperty : 'total',
root : 'data',
idProperty : 'Procedure_RowID'
},
writer : {
type : 'json',
encode : false,
writeAllFields : true
},
api : {
create : _ProcedureHandler.Create_Procedure,
read : _ProcedureHandler.Load_Procedure,
update : _ProcedureHandler.Update_Procedure,
destroy : _ProcedureHandler.Delete_Procedure
},
listeners : {
exception : function(proxy, response, operation)
{
Ext.MessageBox.show(
{
title : 'Remote Exception: Procedure',
msg : operation.getError(),
icon : Ext.MessageBox.ERROR,
buttons : Ext.Msg.OK
});
}
},
afterRequest: function (request, success)
{
if (request.action == 'read')
{
this.readCallback(request, success);
}
else if (request.action == 'create')
{
this.createCallback(request, success);
}
else if (request.action == 'update')
{
this.updateCallback(request, success);
}
else if (request.action == 'destroy')
{
this.deleteCallback(request, success);
}
},
readCallback: function (request, success)
{
if (!request.operation.success)
{
Ext.Msg.show(
{
title : 'Procedure Load Error',
msg : request.operation.getError(),
buttons : Ext.Msg.OK,
icon : Ext.Msg.WARNING
});
}
},
createCallback: function (request, success)
{
if (!request.operation.success && request.operation.hasException())
{
Ext.Msg.show(
{
title : 'Procedure Create Error',
msg : request.operation.getError(),
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
// else
// {
// request.records[0].phantom = true;
// }
},
updateCallback: function (request, success)
{
if (!request.operation.success && request.operation.hasException())
{
console.log(request.records[0]);
request.records[0].rejectChanges();
Ext.Msg.show(
{
title : 'Procedure Update Error',
msg : request.operation.getError(),
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
},
deleteCallback: function (request, success)
{
if (!request.operation.success && request.operation.hasException())
{
Ext.Msg.show(
{
title : 'Procedure Delete Error',
msg : request.operation.getError(),
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
},
scope : this
}
});
It works fine, but my 'problem' comes when I try to add a new row to the grid. I wanted to add a row with out actually calling the create direct method. Is this possible. Below my controller all function:
onAdd : function(btn)
{
var isBlank = false;
this.getProcedureStore().each(function (record)
{
if (record.data['Procedure_RowID'] == 0)
{
Ext.Msg.show(
{
title : 'Warning',
msg : 'Please update the blank procedure first.',
buttons : Ext.Msg.OK,
icon : Ext.Msg.WARNING
});
if (null == record.index)
{
record.index = 0;
}
isBlank = true
this.getProcedureWindow().plugins[0].startEdit(record.index, 1);
return false;
}
}, this);
if (!isBlank)
{
this.getProcedureStore().insert(0, new this.getProcedureModel());
this.getProcedureWindow().plugins[0].startEdit(0, 1);
}
},
Second question is. Once a new record has been saved to the database and the record is returned. How do I update the store. I'm using Procedure_RowID as my key which is sent back by the database and I want it to be update/set in the store for the saved record.