1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    1
    Vote Rating
    0
    handsomesden is on a distinguished road

      0  

    Default Unanswered: checking a store on page refresh in app.js

    Unanswered: checking a store on page refresh in app.js


    login page when get refresh i want to check a store in app.js and then want to load my viewport.


    here is my app.js
    Code:
    Ext.Loader.setConfig({ enabled: true });
    Ext.application({
        name: 'crm',
        appFolder: 'app',
        requires:["Ext.data.Store","Ext.List","Ext.field.Search","Ext.Toolbar"],
        controllers:['Main'],
        /*model: ['User'],
        views: ['Home','Products','Blog', 'Contact','Login'],
        store: ['User'],*/
        launch: function() {
                    
            userdata= Ext.create('crm.store.User',{
                                    model: 'crm.model.User'                  
                                  });
            
            var user = userdata.getAt(0); // when i refresh page and any value is there in this store then it should redirect to my viewport
    
    
            if(user)
            {
                Ext.create('crm.view.Viewport');
            }
            else
            {    
                
                var logform=Ext.create('Ext.form.Panel',{
                        fullscreen: true,
                       id : 'loginFormId',
                       standardSubmit : false,
                       layout: 'vbox',
                       scope : this,
                       url : "test.php",
                        items: [{
                            xtype : 'toolbar',
                            docked: 'top',
                            title: 'Login',
                            cls : 'toolbarcls'
                        },{
                            xtype: 'fieldset',
                            title : ' ',
                            defaults: {
                                labelAlign: 'left',
                                labelWidth: '10%'
                            },
                            //instructions : '',
                            items: [
                                {                            
                                    xtype: 'textfield',
                                    label: '<img src="touch/resources/images/user.png" />',
                                    name : 'user_name',
                                    placeHolder: 'User Name',
                                    useClearIcon: true,
                                    autoCapitalize : false
                                },
                                {
                                    xtype: 'passwordfield',
                                    label: '<img src="touch/resources/images/pswd.png" />',
                                    name : 'password',
                                    placeHolder: 'Password',
                                    useClearIcon: true
                                },
                                {
                                    xtype: 'button',
                                    text: 'Login',
                                    ui: 'confirm',
                                    action: 'submitLogin',
                                    /*data      : logform.getValues(),
                                    record    : logform.getRecord(),*/
                                    
                                }
                                
                            ]
                    }]  ,
                        listeners : {
                                submit : function(form, result)
                                {    
                                    console.log(result);
                                    
                                    if(result.success)
                                    {
                                        var userdata= Ext.create('crm.store.User',{
                                            model: 'crm.model.User'                  
                                          });
                                        
                                        //console.log(crm.store.User);
                                        
                                        userdata.add({ user_id: result.id, user_name: result.user_name });
                                        userdata.sync();
                                        
                                        
                                        console.log(userdata.data.items[0].data.id);
                                        //window.location = 'http://localhost/mobile';
                                    }
                                    else
                                    {
                                        Ext.Msg.alert('Error!',"Wrong Credentials",Ext.emptyFn);    
                                    }
                                },
                                exception : function(form, result){
                                  Ext.Msg.alert('Error!',result.errors.text,Ext.emptyFn);
                                }
                            },
                });
            }
            
        }//END LAUNCH
    });//END APPLICATION[/QUOTE]
    but every time i get "userdata" as undefined

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,649
    Answers
    3454
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Add autoLoad to the store and you will need to listen to the load event for this as loading a store is always async
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1