1. #21
    Sencha User
    Join Date
    Mar 2012
    Posts
    84
    Vote Rating
    0
    suamikim is on a distinguished road

      0  

    Default


    @praveenyk

    I just set up a little sample-project with some basic code to create a MVC-App which shows some static data that is received from Ext-Direct with PHP (see the attached ZIP-File for the full source-code):

    App.js:
    PHP Code:
    Ext.define('TD.Application', {
        
    extend'Ext.app.Application',
        
    name'TD',
        
    appFolder'app',

        
    controllers: [ 'Users' ],

        
    autoCreateViewportfalse,
        
    launch: function() {
            
    Ext.create('TD.view.Viewport');
        }
    });

    Ext.onReady(function() {
        
    Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
        
    Ext.create('TD.Application');
    }); 
    Viewport.js (View):
    PHP Code:
    Ext.define('TD.view.Viewport', {
        
    extend'Ext.container.Viewport',
        
    layout'fit',
        
    items: {
            
    xtype'userlist'
        
    }
    }); 
    User.js (Controller):
    PHP Code:
    Ext.define('TD.controller.Users', {
        
    extend'Ext.app.Controller',

        
    views: [ 'User' ],
        
    stores: [ 'Users' ],
        
    models: ['User']
    }); 
    User.js (View):
    PHP Code:
    Ext.define('TD.view.User' ,{
        
    extend'Ext.grid.Panel',
        
    alias'widget.userlist',

        
    title'All Users',

        
    store'Users',

        
    columns: [
            { 
    header'Name',  dataIndex'name',  flex},
            { 
    header'Email'dataIndex'email'flex}
        ]
    }); 
    User.js (Model):
    PHP Code:
    Ext.define('TD.model.User', {
        
    extend'Ext.data.Model',
        
    fields: [ 'name''email' ]
    }); 
    Users.js (Store):
    PHP Code:
    Ext.define('TD.store.Users', {
        
    extend'Ext.data.Store',
        
    model'TD.model.User',

        
    proxy: {
            
    type'direct',
            
    reader: {
                
    type'json',
                
    root'result'
            
    }
        },

        
    constructor : function(config) {
            
    // The direct-handler-function needs to be applied in the constructor because if we'd do it in the config
            // there would be errors after deployment of the app (see http://www.sencha.com/forum/showthread.php?196544-MVC-direct-proxy-and-load-order)
            
    Ext.applyIf(this.proxy, {
                
    directFnUsers.getAllUsers
            
    });

            
    this.callParent([config]);
        },

        
    autoLoadtrue
    }); 
    Users.php:
    PHP Code:
    <?php
    class Users {
        public function 
    getAllUsers() {
            
    // return some static data...
            
    $users = Array(
                Array(
                    
    "name"  => "Ed",
                    
    "email" => "ed@sencha.com"
                
    ),
                Array(
                    
    "name"  => "Tommy",
                    
    "email" => "tommy@sencha.com"
                
    )
            );

            return 
    $users;
        }
    }

    For further explanations about basic MVC and Ext-Direct stuff, see the guides from ExtJS documentation:
    http://docs.sencha.com/ext-js/4-1/#!...n_architecture
    http://docs.sencha.com/ext-js/4-1/#!...irect_grid_pt1
    Attached Files

  2. #22
    Sencha User
    Join Date
    Apr 2010
    Posts
    75
    Vote Rating
    4
    HriBB is on a distinguished road

      0  

    Default


    I had a similar problem. Solved it by defining direct functions in constructor!

    Code:
    Ext.define('App.model.Type', {
    extend: 'Ext.data.Model',
        idProperty: 'typeId',
        fields: [
            {name: 'typeId', type: 'int'},
            {name: 'type', type: 'string'}
        ],
        proxy: {
            type: 'direct'
        },
        constructor: function() {
            Ext.apply(this.proxy, {
                api: {
                    create  : App.api.Type.create,
                    read    : App.api.Type.read,
                    update  : App.api.Type.update,
                    destroy : App.api.Type.destroy
                }
            });
            this.callParent(arguments);
        }
    
    });

  3. #23
    Sencha User
    Join Date
    Apr 2010
    Posts
    75
    Vote Rating
    4
    HriBB is on a distinguished road

      0  

    Default


    Another solution is to define a custom direct that proxy, that stores function references as strings, and tries to parse api functions on request. I wonder which method is better/faster?

    Code:
    Ext.define('App.data.proxy.Direct', {
    
        extend: 'Ext.data.proxy.Direct',
    
        alias: 'proxy.customdirect',
    
        constructor: function(config){
            var me = this;
            me.callParent(arguments);
            me.directFn = config.directFn;
            me.api = config.api;
        },
    
        getApiFn: function(request) {
            var me = this;
            if (me.api.hasOwnProperty(request.action)) {
                return Ext.direct.Manager.parseMethod(me.api[request.action]);
            } else if (me.directFn) {
                return me.directFn;
            } else {
                return null;
            }
        },
    
        doRequest: function(operation, callback, scope) {
            var me = this,
                writer = me.getWriter(),
                request = me.buildRequest(operation, callback, scope),
                fn = me.getApiFn(request),
                params = request.params,
                args = [],
                method;
    
            //<debug>
            if (!fn) {
                Ext.Error.raise('No direct function specified for this proxy');
            }
            //</debug>
    
            if (operation.allowWrite()) {
                request = writer.write(request);
            }
    
            if (operation.action == 'read') {
                // We need to pass params
                method = fn.directCfg.method;
                args = method.getArgs(params, me.paramOrder, me.paramsAsHash);
            } else {
                args.push(request.jsonData);
            }
    
            Ext.apply(request, {
                args: args,
                directFn: fn
            });
            args.push(me.createRequestCallback(request, operation, callback, scope), me);
            fn.apply(window, args);
        }
    
    });
    This way you can define model proxy with string references

    Code:
    Ext.define('App.model.Type', {
    
        extend: 'Ext.data.Model',
    
        requires: [
            'App.data.proxy.Direct'
        ],
    
        idProperty: 'typeId',
    
        fields: [
            {name: 'typeId', type: 'int'},
            {name: 'type', type: 'string'}
        ],
    
        proxy: {
            type: 'customdirect',
            api: {
                create  : 'App.api.Type.create',
                read    : 'App.api.Type.read',
                update  : 'App.api.Type.update',
                destroy : 'App.api.Type.destroy'
            },
            reader: {
                type: 'json',
                root: 'data',
                idProperty: 'typeId',
                successProperty: 'success',
                messageProperty: 'message'
            },
            writer: {
                type: 'json'
            }
        }
    
    });

  4. #24
    Sencha - Ext JS Dev Team
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    191
    Vote Rating
    37
    nohuhu has a spectacular aura about nohuhu has a spectacular aura about

      1  

    Default


    In 4.2, this problem is solved: Direct proxy API functions are resolved at first call attempt instead of construction time.

    Regards,
    Alex.

  5. #25
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    12
    Vote Rating
    2
    ukjbrown is on a distinguished road

      0  

    Default


    Quote Originally Posted by HriBB View Post
    Another solution is to define a custom direct that proxy, that stores function references as strings, and tries to parse api functions on request. I wonder which method is better/faster?
    Thanks! Finally I have Ext Direct wired up.

    I can't believe how much time I have wasted attempting to get Ext Direct to work. I really don't understand Sencha's position on this, should we not be using Ext.application({}) as recommended...? Since there doesn't appear to be a way (out of the box) to get Ext Direct to work without extending the framework as suggested by HriBB.

    I was simply going around in circles either resulting in the method being unresolved or directCfg being unresolved. Crazy!

    It makes more sense to define the remoting methods as Strings anyhow, especially when using an IDE that attempts to resolve function / object instances in the project.

  6. #26
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Brisbane, QLD, Australia
    Posts
    45
    Vote Rating
    3
    ampro is on a distinguished road

      0  

    Default


    Quote Originally Posted by nohuhu View Post
    In 4.2, this problem is solved: Direct proxy API functions are resolved at first call attempt instead of construction time.
    And hopefully for Touch 2.2 as well?

    A security feature wish of mine is that I use use plain AJAX or whatever to do login authentication and then only permit loading the Direct RPC API once authenticated. This obviously requires delayed binding to stores which hopefully this recent fix will now support (right?).

  7. #27
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Brisbane, QLD, Australia
    Posts
    45
    Vote Rating
    3
    ampro is on a distinguished road

      0  

    Default


    Code:
    Just init your Ext.Direct API in Application's constructor and it'll be fine.
    
    FYI ... I found that this solution triggered another (rather worrying) exception in my ST 2.1.1 app ...

    In Ext.setup() .... Ext.event was undefined when the factoryConfig callback fired.

    Code:
            Ext.onDocumentReady(function() {
                Ext.factoryConfig(config, function(data) {
                    Ext.event.Dispatcher.getInstance().setPublishers(data.eventPublishers);
    This is interesting because it suggests that there might be a race condition as just a few lines before is code that should have defined the value if it was performed before the callback fired:

    Code:
     Ext.require(['Ext.event.Dispatcher']);

  8. #28
    Sencha - Ext JS Dev Team
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    191
    Vote Rating
    37
    nohuhu has a spectacular aura about nohuhu has a spectacular aura about

      1  

    Default


    That advice you quoted was aimed at Ext JS apps; Sencha Touch has a wee bit different Ext.Direct implementation and I'm not 100% sure it works the same way. So please take it with a grain of salt.

    Regards,
    Alex.

  9. #29
    Sencha User
    Join Date
    Sep 2013
    Posts
    1
    Vote Rating
    0
    uv_chanti is on a distinguished road

      0  

    Default Can we load Tree Store With Json String returned by Java Class With direcr Proxy ?

    Can we load Tree Store With Json String returned by Java Class With direcr Proxy ?


    Hi,
    I am trying to load tree store dynamically with direct proxy with json string returned by my java class. But my store is not loaded.


    My Store:
    root:{
    expanded: true,
    text:'Total
    },
    proxy:{
    type:'direct',
    directFn:type.getTreeData,
    reader:{
    type:'json',
    root:'market'
    },
    writer:{
    type:'json'
    }
    }

    Return JSON as follows:


    [{"root":"Total",
    "children":[{"market":"Electronics","value":125.23,
    "children":[
    {"market":"abc","value":12.25},
    {"market":"silver","value":12.25},
    {"market":"hsb","value":12.25}
    ]},
    {"market":"Gold","value":14.25,
    "children":[
    {"market":"ckl","value":258.25},
    {"market":"magnet","value":45.25},
    {"market":"qpoid","value":112.25}
    ]}
    ]}
    ]

    Any one tell me why my store is not loading.

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..."