Results 1 to 7 of 7

Thread: Passing Model Properties to custom Proxy

  1. #1

    Default Passing Model Properties to custom Proxy

    Hi there,

    maybe I'm a bit nearsighted, but I can't find out, how a custom property defined in a Model class can be passed to the proxy defined for this model.

    For short: My server API uses commands to request data. So my idea was, to define a command for this model and pass it to the proxy of this model. But I had no luck to get this working. Maybe it's a timing problem??

    This is the definition of my custom proxy :
    Code:
    Ext.define('BICsuite.proxy.CommandProxy', {
        extend: 'Ext.data.proxy.Ajax',
        alias: 'proxy.commandproxy',
    
    
        directionParam: null,
        filterParam: null,
        groupDirectionParam: null,
        groupParam: null,
        limitParam: null,
        pageParam: null,
        sortParam: null,
        startParam: null,
    
    
        COMMAND: null,
    
    
        getCurrentSessionInfo: function() {
            var win = Ext.WindowManager.getActive();
            if (win) {
                return win.sessionInfo;
            }
        },
    
    
        buildUrl: function(request) {
            return '/python/execute.py/execute';
        },
    
    
        buildRequest: function(operation) {
    
    
            var sessionInfo = this.getCurrentSessionInfo();
            var request = this.callParent(arguments);
            request.config.method = 'POST';
    
    
            request.config.params.HOST = sessionInfo.SessionData.Host;
            request.config.params.PORT = sessionInfo.SessionData.Port;
            request.config.params.USER = sessionInfo.SessionData.UserName;
            request.config.params.PASS = sessionInfo.SessionData.Password;
            request.config.params.COMMAND = this.COMMAND;
    
    
            return request;
        }
    
    
    });
    Then there is a base model, that implements this proxy:

    Code:
    Ext.define('BICsuite.model.base.BaseModel', {
        extend: 'Ext.data.Model',
        requires: [
            'BICsuite.proxy.CommandProxy'
        ],
        COMMAND: null,
        rootProperty: null,
    
    
        idProperty: 'ID',
        fields: [{
            name: 'ID',
            type: 'string'
        }],
    
    
        schema: {
            namespace: 'BICsuite.model', // generate auto entityName
            command: this.COMMAND,
            root: this.rootProperty,
            proxy: {
                type: 'commandproxy',
                COMMAND: this.COMMAND,
    
    
                reader: {
                    type: 'json',
                    rootProperty: this.rootProperty
                }
            }
        }
    
    
    });
    This is extended by the concrete model, where I've defined the COMMAND and the rootProperty, that varies for the results of different commands:

    Code:
    Ext.define('BICsuite.model.user.UserListModel', {
        extend: 'BICsuite.model.base.BaseModel',
    
    
        COMMAND: 'list user',
        rootProperty: 'DATA.TABLE',
        fields: [
            "ID", "NAME", "IS_ENABLED", "DEFAULT_GROUP", "PRIVS"
        ]
    });
    Then I will call this via a store in the viewmodel:

    Code:
       Ext.define('BICsuite.view.user.UserViewModel', {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.userviewmodel',
        requires: [
            'BICsuite.model.user.UserListModel'
        ],
    
    
        fields: [
            "ID", "NAME", "IS_ENABLED", "DEFAULT_GROUP", "PRIVS"
        ],
        idProperty: 'ID',
        stores: {
            Users: {
                model: 'BICsuite.model.user.UserListModel',
                autoLoad: true,
        },
    });

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    Code:
        schema: {
            namespace: 'BICsuite.model', // generate auto entityName
            command: this.COMMAND,
            root: this.rootProperty,
            proxy: {
                type: 'commandproxy',
                COMMAND: this.COMMAND,
    
    
                reader: {
                    type: 'json',
                    rootProperty: this.rootProperty
                }
            }
        }
    this is not the model, it's window.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3

    Default

    I don't understand, what you mean? schema is defined in my base model!
    But the related view is a subitem of a window, if this is what you mean...
    Last edited by fehrenhuber; 6 Aug 2016 at 12:49 AM. Reason: Additional Information

  4. #4
    Sencha User
    Join Date
    Apr 2013
    Posts
    908
    Answers
    105

    Default

    Quote Originally Posted by fehrenhuber View Post
    I don't understand, what you mean? schema is defined in my base model!
    But the related view is a subitem of a window, if this is what you mean...
    He means that "this" in "this.COMMAND" and "this.rootProperty" is global window object, not your model instance.

  5. #5

    Default

    Ah ok, sorry, that was a semantic misunderstanding. But how can I get the property from my model?

  6. #6
    Sencha User
    Join Date
    Apr 2013
    Posts
    908
    Answers
    105

    Default

    Quote Originally Posted by fehrenhuber View Post
    Ah ok, sorry, that was a semantic misunderstanding. But how can I get the property from my model?
    You can try something like the following code:
    PHP Code:
    Ext.define('BICsuite.model.user.UserListModel', {
        
    extend'BICsuite.model.base.BaseModel',
        
    fields: ["ID""NAME""IS_ENABLED""DEFAULT_GROUP""PRIVS"],
        
    proxy: {
            
    COMMAND'list user',
            
    reader: {
                
    type'json',
                
    rootProperty'DATA.TABLE'
            
    }
        }
    });

    Ext.define('BICsuite.model.base.BaseModel', {
        
    extend'Ext.data.Model',
        
    requires: ['BICsuite.proxy.CommandProxy'],
        
    idProperty'ID',
        
    fields: [{
            
    name'ID',
            
    type'string'
        
    }],
        
    schema: {
            namespace: 
    'BICsuite.model',
            
    proxy: {
                
    type'commandproxy',
                
    COMMANDnull,
                
    reader: {
                    
    type'json',
                    
    rootPropertynull
                
    }
            }
        }
    }); 

  7. #7

    Default

    Thank you hakimio!! I've thought about this solution before, but from my opinion it is not ideal from an OOP point of view, as this does not provide a complete encapsulation. I know that proxy is a separate object, but I don't know how to access the model from where it is instantiated. Does anyone know how to do that, or is this not possible yet?

Similar Threads

  1. Replies: 2
    Last Post: 19 Feb 2015, 4:49 AM
  2. Replies: 1
    Last Post: 10 May 2013, 7:28 AM
  3. Replies: 2
    Last Post: 7 Aug 2012, 10:08 AM
  4. Save model passing itself to the proxy
    By nextSTEP in forum Ext: Q&A
    Replies: 2
    Last Post: 29 Sep 2011, 2:23 AM
  5. Configuring proxy based on model properties
    By onsela in forum Sencha Touch 1.x: Discussion
    Replies: 0
    Last Post: 7 Feb 2011, 5:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •