1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    25
    Answers
    1
    Vote Rating
    1
    delebash is on a distinguished road

      0  

    Default Answered: How to make a store that inherits from a common store?

    Answered: How to make a store that inherits from a common store?


    I followed this code to make a common proxy and it worked great, except that the store properties where not inherited such as auto sync. So I am trying to follow the same principle but instead of defining proxy as type I am using store instead but I can't get it to work. It says users is undefined when I try to load the store in my controller.

    Here is my common store definition
    Code:
    var crudServiceBaseUrl = "http://127.0.0.1:8081/cors/";
    
    Ext.define('SimplyFundraising.store.SFStore', {
        alias: 'SFStore',
        extend : 'Ext.data.Store',
        autoLoad : false,
        autoSync : true,
    
    
        proxy : {
            directionParam : null,
            filterParam : null,
            groupDirectionParam : null,
            groupParam : null,
            limitParam : null,
            pageParam : null,
            sortParam : null,
            startParam : null,
    
            api : {
                create : crudServiceBaseUrl + '/{entity}/?$method=update',
                read : crudServiceBaseUrl + '/{entity}',
                update : crudServiceBaseUrl + '/{entity}/?$method=update',
                destroy : crudServiceBaseUrl + '/{entity}({id})/?$method=delete',
            },
            reader : {
                type : 'json',
                root : '__ENTITIES',
                successProperty : false,
                getResponseData : function(response) {
                    var findme = "__ENTITIES";
                    if (response.responseText.indexOf(findme) > -1) {
                        //Already an array of __ENTITIES
                    } else {
                        //Single result turn into array __ENTITIES
                        response.responseText = '{"__ENTITIES":[' + response.responseText + ']}';
                    }
                    var data = Ext.data.reader.Json.prototype.getResponseData.call(this, response);
                    return data;
                }
            },
            writer : {
                type : 'json',
                writeAllFields : false,
                getRecordData : function(record, operation) {
                    switch(operation.action) {
                        case 'create':
                            console.log('INFO', 'Create');
                            delete record.data.__KEY
                            delete record.data.__STAMP
                            return record.data
                            break;
                        case 'update':
                            console.log('INFO', 'Updating');
                            var myrecord = record.getChanges();
                            myrecord.__KEY = record.data.__KEY
                            myrecord.__STAMP = record.data.__STAMP
                            return myrecord
                            break;
                    }
                }
            }
        },
    
        buildUrl : function(request) {
            var url = this.callParent(arguments);
            return this.replaceTokens(url, request);
        },
    
        replaceTokens : function(str, request) {
            var me = this;
    
            return str.replace(/{(.*?)}/g, function(full, token) {
                // We read the id from the request params, the category is read from the proxy itself
                return encodeURIComponent(request.params[token] || me[token]);
            });
        }
    });
    Here is the user specific store
    Code:
    Ext.define('SimplyFundraising.store.Users', { 
        type: 'store.SFStore',
        model : 'SimplyFundraising.model.User',
         proxy: { 
            entity: 'Users'
        } 
    });
    Any ideas on what I am doing wrong?

    Thanks,
    Dan

  2. Have your Users store extend: 'SimplyFundraising.store.SFStore'.

    Also, when you set an alias on a store you should use the syntax store.alias (alias: 'store.SFStore').

  3. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,005
    Answers
    381
    Vote Rating
    183
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    Have your Users store extend: 'SimplyFundraising.store.SFStore'.

    Also, when you set an alias on a store you should use the syntax store.alias (alias: 'store.SFStore').

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    25
    Answers
    1
    Vote Rating
    1
    delebash is on a distinguished road

      0  

    Default


    Thank you, that worked!

Thread Participants: 1

Tags for this Thread