Hybrid View

  1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    24
    Vote Rating
    0
    anthonykulis is on a distinguished road

      0  

    Default Using direct proxy with extraParams

    Using direct proxy with extraParams


    This seems like it should be really simple, so I think I am just missing something obvious. When using a direct proxy we can set our read op to use extraParams but what I want to know is can we send extraParams using the create, update, and destroy calls?

    Example:
    Code:
            Ext.define('Behave.models.ReportCategory', {
    
                extend: 'Ext.data.Model',
    
                fields: [
                    {name: 'id', mapping: 'BEHAVE-REPORT-CATEGORY_id'},
                    {name: 'text', mapping: 'BEHAVE-REPORT-CATEGORY_text'},
                    {name: 'description', mapping: 'BEHAVE-REPORT-CATEGORY_description'}
                ],
    
                proxy: {
                    type: 'direct',
                    api: {
                        create: Behave.ReportController.tempCatchAll,
                        read: Behave.ReportCategoryController.getCategories,
                        update: Behave.ReportController.tempCatchAll
    
                    },
                    extraParams: {
                        sessionpwd: kms.getTokenizedKey()
                    },
                    reader: {
                        type: 'json',
                        root: 'data'
                    },
                    simpleSortMode: true
                }
    
            });
    The above will execute the read with the sessionpwd property but will not for any other op. How can I do this when my store autoSyncs?

    Code:
        var categoryStore = Ext.create('Ext.data.Store', {
    
            model: 'Behave.models.ReportCategory',
            sorters: [{property: 'BEHAVE-REPORT-CATEGORY_text', direction: 'ASC'}],
            autoLoad: true,
            autoSync: true
        });
    Last edited by anthonykulis; 26 Jul 2011 at 5:32 AM. Reason: code tags

  2. #2
    Sencha User
    Join Date
    Nov 2010
    Posts
    24
    Vote Rating
    0
    anthonykulis is on a distinguished road

      0  

    Default Really?

    Really?


    So far I have 130 views on this. No one can help? I guess I will have to manually handle this then

  3. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    5
    Vote Rating
    1
    jefftrull is on a distinguished road

      0  

    Default


    I am observing exactly the same issue and I hope you will share a workaround if you find one

    (Sencha devs: compare the treatment of extraParams in today's DirectProxy.doRequest vs. baseParams in 3.4's Store.execute. In 3.4, baseParams made it into all four CRUD actions, but now extraParams is only applied to reads).

  4. #4
    Sencha User
    Join Date
    Sep 2010
    Posts
    5
    Vote Rating
    1
    jefftrull is on a distinguished road

      1  

    Default


    So here is my workaround:

    Code:
                Ext.define('MyNS.writer', {
                    extend: 'Ext.data.writer.Json',
                    alias: 'writer.mine',
                    config: {extraParams: undefined},
                    constructor: function(config) {
                        this.callParent([config]);
                    },
                    writeRecords: function(request, data) {
                        this.callParent([request, data]);
                        if ((this.extraParams !== undefined) && (this.extraParams instanceof Object)) {
                            Ext.apply(request.jsonData, this.extraParams);
                        }
                        return request;
                    }});
    And for the "writer" config of my proxy I use "mine", the alias I defined above, and supply my extraParams there too.

    Note that I'm using encode: false and allowSingle: false; my writeRecords is not properly general. I would look at the POST in Firebug and figure out where your params need to be.

  5. #5
    Sencha User j.bruni's Avatar
    Join Date
    Jun 2009
    Location
    Uberlândia, MG, Brazil
    Posts
    105
    Vote Rating
    7
    j.bruni is on a distinguished road

      0  

    Default


    Quote Originally Posted by jefftrull View Post
    So here is my workaround:
    Brilliant! Thanks a lot.

  6. #6
    Ext JS Premium Member
    Join Date
    Jun 2009
    Posts
    250
    Vote Rating
    2
    Hacker-CB is on a distinguished road

      0  

    Default


    jsonData can be array if it is batch, so better way will be:
    Code:
    writeRecords: function (request, data) {
            this.callParent([request, data]);
            if ((this.extraParams !== undefined) && (this.extraParams instanceof Object)) {
                if (Ext.isArray(request.jsonData)){
                    for (var i=0; i<request.jsonData.length; i++){
                        Ext.apply(request.jsonData[i], this.extraParams);
                    }
                } else {
                    Ext.apply(request.jsonData, this.extraParams);
                }
            }
            return request;
        }

  7. #7
    Sencha Premium Member
    Join Date
    Feb 2009
    Location
    Boca Raton, FL
    Posts
    94
    Vote Rating
    1
    jimmifett is on a distinguished road

      0  

    Default


    I used to use a nasty override of Ext.direct.RemotingProvider.getCallData and .sendFormRequest to put tokens in the packet, but a couple weeks ago I looked into the matter more thoroughly and came up with this much better approach that is less likely to break in the future. It moves the tokens out of band from the packet and into the http headers.

    PHP Code:
    if(Ext.Ajax.defaultHeaders){
        
    Ext.apply(Ext.Ajax.defaultHeaders, {
            
    'ExtCSRFToken' mySessionKey
        
    });
    }
    else{
        
    Ext.Ajax.defaultHeaders = {
            
    'ExtCSRFToken' mySessionKey
        
    };