Results 1 to 2 of 2

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

  1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    1
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Posting Permissions

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