1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    12
    Vote Rating
    0
    zero10 is on a distinguished road

      0  

    Default Using a custom proxy in the designer

    Using a custom proxy in the designer


    I admittedly am pretty new to using the Sencha designer but I decided to give the beta of version 2 a try and I am having trouble figuring something out. I am using a custom proxy that is based heavily on a json proxy I found on these very forums:

    Code:
    Ext.define('Ext.data.JsonProxy', {
        extend: 'Ext.data.AjaxProxy',
        alias: 'proxy.json',
        store: 'Afes',
        doRequest: function(operation, callback, scope) {
            var writer  = this.getWriter(),
                request = this.buildRequest(operation, callback, scope);
                
            if (operation.allowWrite()) {
                request = writer.write(request);
            }
            
            Ext.apply(request, {
                headers       : this.headers,
                timeout       : this.timeout,
                jsonData      : request.params,
                scope         : this,
                callback      : this.createRequestCallback(request, operation, callback, scope),
                method        : this.getMethod(request),
                disableCaching: false // explicitly set it to false, ServerProxy handles caching
            });
            
            delete request.params;
            
            Ext.Ajax.request(request);
            
            return request;
        },
        constructor: function() {
            Ext.data.JsonProxy.superclass.constructor.apply(this, arguments);
            this.actionMethods.read = 'POST';
        }
    });
    That I have just thrown at the top of my app.js (I know, this is a bad idea, I am trying to figure out the correct way to use it). I can then use this proxy as follows:
    Code:
    Ext.define('AN.store.Afes', {
        extend: 'Ext.data.Store',
        model: 'AN.model.Afe',
        storeId: 'afeStore',
        autoLoad: false,
        proxy: {
            type: 'json',
            reader: {
                type: 'json',
                root: 'd.AllRows',
                successProperty: 'success',
                totalProperty: 'total'
            },
            api: {
            create: 'jsonsvc/TestCall',
            read: '/jsonsvc/TestCall',
            update: 'jsonsvc/TestCall',
            destroy: 'jsonsvc/TestCall'
        },
        }
    });

    Things work like this, however when I try to implement these models and stores and controllers in the designer I am only able to use a normal ajax proxy, and I seem to be unable to create my own proxy type. I use this proxy on a large number of different stores if that matters.

    Can somebody please tell me, what is the right way to use this proxy? Is it even possible to do within the designer?

  2. #2
    Sencha User
    Join Date
    Feb 2012
    Posts
    117
    Vote Rating
    11
    Sottilde will become famous soon enough

      0  

    Default


    Since we started our project, we copied designer.html (now app.html) to index.html and added our own code.

    We haven't been able to get Ext.Loader to operate correctly with Designer but you can just load overridden classes manually. Adding your overridden proxy before designer.js in index.html should work.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    12
    Vote Rating
    0
    zero10 is on a distinguished road

      0  

    Default


    So you would then edit all of the code files by hand after using the designer to choose the json proxy type?

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    117
    Vote Rating
    11
    Sottilde will become famous soon enough

      0  

    Default


    No, because by overwriting the alias "proxy.json", you overwrite the alias originally used by the JSON proxy, thus moving all existing and future proxies of type: "json" to your new proxy.

  5. #5
    Sencha User
    Join Date
    Mar 2012
    Posts
    12
    Vote Rating
    0
    zero10 is on a distinguished road

      0  

    Default


    Proxy type json did not exist prior to the code above, only 'ajax'. From what you have said it sounds like I can change the proxy type to be ajax and continue to connect things in the designer as if I am using the provided ajax proxy (as the interface of my proxy is unchanged) and it should work, overwriting the provided ajax proxy when the relevant .js file is included. Thanks for the advice, I will try it out

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    117
    Vote Rating
    11
    Sottilde will become famous soon enough

      0  

    Default


    Quote Originally Posted by zero10 View Post
    Proxy type json did not exist prior to the code above, only 'ajax'. From what you have said it sounds like I can change the proxy type to be ajax and continue to connect things in the designer as if I am using the provided ajax proxy (as the interface of my proxy is unchanged) and it should work, overwriting the provided ajax proxy when the relevant .js file is included. Thanks for the advice, I will try it out
    My apologies, I didn't go through the proxy code you posted up top. If you're going to use the JsonProxy exclusively, I would just overwrite the ajax proxy for now until 3rd party lib support is in SD.

  7. #7
    Sencha User
    Join Date
    Mar 2012
    Posts
    12
    Vote Rating
    0
    zero10 is on a distinguished road

      0  

    Default


    The reason I have to do this is because the service I am interfacing with does not accept the parameters in what would be considered the normal way, they have to be provided with the jsondata property on the ajax reader. There is no way to set the jsondata property on a normal ajax proxy.

Thread Participants: 1