2012-02-16 79 views
0

我有一个带有两个项目的视口:一个认证表单和一个选项卡面板。 在这个视口的initComponent方法中,我调用一个函数来检查用户是否输入了他的登录名和密码。使用setActiveItem时的白色屏幕

如果没有,则会显示身份验证表单,当他单击登录按钮时,会显示选项卡面板。

但是,如果有存储的凭据,我希望应用程序自动切换到选项卡面板。

这是我想要做的:

app.views.Viewport = function (config) { 
    Ext.apply(this, config); 

    this.user = null; // Setter par le checkLogin ! 

    this.bottomTabs = new Ext.TabPanel({ 
     tabBar: { 
      dock: 'bottom', 
      layout: { pack: 'center' } 
     }, 
     items:[...],        
     layout: 'fit', 
     cardSwitchAnimation: false, 
    }); 

    this.userLogin = new app.views.UserLogin(); 

    //constructor 
    app.views.Viewport.superclass.constructor.call(this, { 
     fullscreen: true, 
     layout: 'card', 
     cardSwitchAnimation: 'fade', 
     items: [ 
      this.userLogin, 
      this.bottomTabs 
     ] 
    }); 

}; 

Ext.extend(app.views.Viewport, Ext.Panel, { 
    initComponent: function() { 
     app.views.Viewport.superclass.initComponent.call(this); 
     this.initialCheck(); 
    }, 

    initialCheck: function(){ 
     console.log('init'); 
     var credentials = window.localStorage.getItem("neroApp_credentials"); 
     if (credentials == null || credentials == "reset") { 
      console.log('no creds'); 
      this.setActiveItem(this.userLogin); // *** 
     } 
     else { 
      console.log('creds'); 
      Ext.Ajax.defaultHeaders = {'Authorization':"Basic " + credentials}; 
      this.checkLogin(); 
     } 
    }, 

    checkLogin: function() { 
     console.log('checkLogin'); 
     Ext.Ajax.request({ 
      url: app.stores.baseAjaxURL + '&jspPage=%2Fajax%2FgetUser.jsp', 
      scope: this, 
      success: function(response, opts) { 
       console.log('success'); 
       var user = Ext.decode(response.responseText); 
       this.user = user; 
       this.actualites.actualitesList.refreshActu(this.user, parseInt(window.localStorage.getItem("newsPerLoad"))); 
       this.setActiveItem(this.bottomTabs, { type: 'fade', duration: 500 }); 
      }, 
      failure: function(response, opts) { 
       console.log('failure'); 
      } 
     }); 
    }, 

    resetLogin: function() { 
     window.localStorage.setItem("neroApp_credentials", "reset"); 
     Ext.Ajax.defaultHeaders = {'Authorization':"Basic RESET_Credentials"}; 
    } 

}); 

但我发现了一个白色的屏幕上,因为*线的启动。我猜测它被触发得太早可能是因为checkLogin函数中的setActiveItem工作正常。

有人有一个想法,为什么这个setActiveItem引发错误?

感谢

回答

0

好吧,我没有发现什么问题了,即使我猜测,烧制initComponent内setActiveItem不是很好的做法,但我终于得到它通过设置工作活动项目如下:

initialCheck: function(){ 
     console.log('init'); 
     var credentials = window.localStorage.getItem("neroApp_credentials"); 
     if (credentials == null || credentials == "reset") { 
      this.activeItem = this.userLogin; 
     } 
     else { 
      this.activeItem = this.bottomTabs; 
      Ext.Ajax.defaultHeaders = {'Authorization':"Basic " + credentials}; 
      this.checkLogin(); 
     } 
    },