-
24 Aug 2011 4:00 AM #1
Answered: Store Sync Response
Answered: Store Sync Response
Hi,
I have a Ext.data.Store on which I doing a sync.
My sync works ok and I return some JSON. I can see the response in Firebug, but how do I use the response JSON?
I've looked at the examples, looked through the forum and the internet, but cannot see how to do this.
Below is the code I use for my store. If anyone is interested, i'm using the Bryntum Scheduler.
PHP Code:eventStore : Ext.create("Ext.data.Store", {
idProperty : 'Id',
model : 'Sch.model.Event2',
autoLoad: true,
proxy: {
type: 'ajax',
api: {
create: '/cgi-bin/EV_Rostering_Shifts_Save_New.pl', // Called when saving new records
read: '/cgi-bin/EV_Rostering_Events_Get.pl?branch=' + branch + '&view=' + view,
update: '/cgi-bin/EV_Rostering_Shifts_Save_Update.pl', // Called when updating existing records
destroy: 'myBackend.php?action=destroy' // Called when deleting existing records
},
reader: {
type: 'json',
model : 'Sch.model.Event2'
},
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: true,
root: 'data'
}),
timeout: 10000
},
listeners: {
//add
add: function(store, records, index, options)
{
},
update: function(store, records, index, options)
{
}
//remove
//update
}
}),
-
Best Answer Posted by tomearly
I've worked it out.
I've added an exception listener to the store and can then access the response upon syncing the store.
Something like this:-
PHP Code:eventStore : Ext.create("Ext.data.Store", {
idProperty : 'Id',
model : 'Sch.model.Event2',
autoLoad: true,
proxy: {
type: 'ajax',
api: {
create: '/cgi-bin/EV_Rostering_Shifts_Save_New.pl', // Called when saving new records
read: '/cgi-bin/EV_Rostering_Events_Get.pl?branch=' + branch + '&view=' + view,
update: '/cgi-bin/EV_Rostering_Shifts_Save_Update.pl', // Called when updating existing records
destroy: 'myBackend.php?action=destroy' // Called when deleting existing records
},
reader: {
type: 'json',
model : 'Sch.model.Event2'
},
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: true,
root: 'data'
}),
timeout: 10000,
listeners: {
exception: function(proxy, res) {
//console.log(proxy);
//console.log(type);
var responseObj = Ext.JSON.decode(res.responseText);
var success = responseObj.success;
if(success == true)
{
EV.Rostering.Grid.eventStore.commitChanges();
EV.Rostering.Grid.eventStore.load();
}
else
{
alert('Unable to save shift(s)');
}
}
}
}
})
-
24 Aug 2011 11:07 AM #2
store
store
Take a look at the store.write event for successfull update, for errors there is the proxy exception event.
-
24 Aug 2011 11:23 AM #3
Hi,
Thank you for the reply. Yes this is good for knowing if it was successful and is partly what I need.
When I have done the sync, I return some JSON from the script that processes the sync data.
I want to be able to use this data to
1) determine a success or failure ( and a reason )
2) to be able to return data to update the store ( this will contain IDs that are generated but the DB )
Any ideas how I can do this?
Thanks,
Tom
-
25 Aug 2011 5:23 AM #4
I've worked it out.
I've added an exception listener to the store and can then access the response upon syncing the store.
Something like this:-
PHP Code:eventStore : Ext.create("Ext.data.Store", {
idProperty : 'Id',
model : 'Sch.model.Event2',
autoLoad: true,
proxy: {
type: 'ajax',
api: {
create: '/cgi-bin/EV_Rostering_Shifts_Save_New.pl', // Called when saving new records
read: '/cgi-bin/EV_Rostering_Events_Get.pl?branch=' + branch + '&view=' + view,
update: '/cgi-bin/EV_Rostering_Shifts_Save_Update.pl', // Called when updating existing records
destroy: 'myBackend.php?action=destroy' // Called when deleting existing records
},
reader: {
type: 'json',
model : 'Sch.model.Event2'
},
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: true,
root: 'data'
}),
timeout: 10000,
listeners: {
exception: function(proxy, res) {
//console.log(proxy);
//console.log(type);
var responseObj = Ext.JSON.decode(res.responseText);
var success = responseObj.success;
if(success == true)
{
EV.Rostering.Grid.eventStore.commitChanges();
EV.Rostering.Grid.eventStore.load();
}
else
{
alert('Unable to save shift(s)');
}
}
}
}
})


Reply With Quote