1. #1
    Sencha User
    Join Date
    Nov 2009
    Location
    Milton Keynes, England
    Posts
    18
    Answers
    2
    Vote Rating
    0
    tomearly is on a distinguished road

      0  

    Question 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',
                                    
    autoLoadtrue,
                                    
    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,
                                                    
    writeAllFieldstrue,
                                                    
    root'data'
                                           
    }),
                                           
    timeout10000
                                    
    },
                                    
    listeners: {
                                            
    //add
                                            
    add: function(storerecordsindexoptions)
                                            {
                                            },
                                            
    update: function(storerecordsindexoptions)
                                            {
                                            }
                                            
    //remove
                                            //update
                                    
    }
                                }), 

  2. 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',
                                    
    autoLoadtrue,
                                    
    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,
                                                    
    writeAllFieldstrue,
                                                    
    root'data'
                                           
    }),
                                           
    timeout10000,
                                            
    listeners: {
                                                    
    exception: function(proxyres) {
                                                            
    //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)');
                                                            }
                                                    }
                                            }
                                    }
                                }) 

  3. #2
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Answers
    1
    Vote Rating
    2
    ValterBorges is on a distinguished road

      0  

    Default store

    store


    Take a look at the store.write event for successfull update, for errors there is the proxy exception event.

  4. #3
    Sencha User
    Join Date
    Nov 2009
    Location
    Milton Keynes, England
    Posts
    18
    Answers
    2
    Vote Rating
    0
    tomearly is on a distinguished road

      0  

    Default


    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

  5. #4
    Sencha User
    Join Date
    Nov 2009
    Location
    Milton Keynes, England
    Posts
    18
    Answers
    2
    Vote Rating
    0
    tomearly is on a distinguished road

      0  

    Lightbulb


    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',
                                    
    autoLoadtrue,
                                    
    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,
                                                    
    writeAllFieldstrue,
                                                    
    root'data'
                                           
    }),
                                           
    timeout10000,
                                            
    listeners: {
                                                    
    exception: function(proxyres) {
                                                            
    //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)');
                                                            }
                                                    }
                                            }
                                    }
                                }) 

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi