Jez D
Jez D

Reputation: 1489

Sencha Touch Active Item

New to Sencha, I have a login form which works well and posts the form elements as required via ajax. onSuccess, it stores data in localStorage.token and then move to the next page. What I would like is that when the app loads, if there is already data in localStorage.token, then it goes straight to the second page. I tried setActiveItem, but that did not have the desired result.

Here is my app.js:

    //<debug>
Ext.Loader.setPath({
    'Ext': 'touch/src'
});
//</debug>

Ext.application({
    name: 'axis3',
    //profiles: ['Phone', 'Tablet', 'Desktop'],


    requires: [
        'Ext.MessageBox'
    ],

    views: ['Login','Main'],
    controllers:['Login','Main'],

    icon: {
        '57': 'resources/icons/Icon.png',
        '72': 'resources/icons/Icon~ipad.png',
        '114': 'resources/icons/[email protected]',
        '144': 'resources/icons/[email protected]'
    },

    isIconPrecomposed: true,

    startupImage: {
        '320x460': 'resources/startup/320x460.jpg',
        '640x920': 'resources/startup/640x920.png',
        '768x1004': 'resources/startup/768x1004.png',
        '748x1024': 'resources/startup/748x1024.png',
        '1536x2008': 'resources/startup/1536x2008.png',
        '1496x2048': 'resources/startup/1496x2048.png'
    },

    launch: function() {
        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();
        // Initialize the login view
        Ext.Viewport.add([
            { xtype: 'loginview' },
            { xtype: 'mainview' }
        ]);
        Ext.Ajax.setUseDefaultXhrHeader(false);// needed to enable cross domain request.
    },

    onUpdated: function() {
        Ext.Msg.confirm(
            "Application Update",
            "This application has just successfully been updated to the latest version. Reload now?",
            function(buttonId) {
                if (buttonId === 'yes') {
                    window.location.reload();
                }
            }
        );
    }
});

Thanks for any assistance

Upvotes: 1

Views: 688

Answers (1)

kevhender
kevhender

Reputation: 4405

I would just add the one view that you need, based on the result of your token check:

launch: function() {
    // Destroy the #appLoadingIndicator element
    Ext.fly('appLoadingIndicator').destroy();

    var hasToken = this.hasToken();
    if (hasToken)
        Ext.Viewport.setActiveItem({ xtype: 'mainview' });
    else
        Ext.Viewport.setActiveItem({ xtype: 'loginview' });

    Ext.Ajax.setUseDefaultXhrHeader(false);// needed to enable cross domain request.
},

Upvotes: 1

Related Questions