improve event handling

This commit is contained in:
Sebastian Sdorra
2011-03-06 14:14:55 +01:00
parent 3b1d7a23d2
commit 4c22d0a62a
2 changed files with 31 additions and 9 deletions

View File

@@ -62,11 +62,17 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
mainTabPanel: null,
constructor : function(config) {
this.addEvents("login", "logout");
this.addEvents('login', 'logout');
this.mainTabPanel = Ext.getCmp('mainTabPanel');
this.addListener('login', this.postLogin, this);
Sonia.scm.Main.superclass.constructor.call(this, config);
},
postLogin: function(){
this.createMainMenu();
this.createRepositoryPanel();
},
createRepositoryPanel: function(){
if ( debug ){
console.debug('create repository panel');
@@ -303,6 +309,18 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
Ext.Msg.alert(this.logoutFailedText);
}
});
},
addListeners: function(event, callbacks){
Ext.each(callbacks, function(callback){
if ( Ext.isFunction(callback) ){
this.addListener(event, callback);
} else if (Ext.isObject(callback)) {
this.main.addListener(event, callback.fn, callback.scope);
} else if (debug){
console.debug( "callback is not a function or object. " + callback );
}
});
}
});
@@ -360,11 +378,7 @@ Ext.onReady(function(){
main.addTabPanel(id, xtype, title);
}
// register login callbacks
// create menu
loginCallbacks.splice(0, 0, {fn: main.createMainMenu, scope: main});
// add repository tab
loginCallbacks.push({fn: main.createRepositoryPanel, scope: main});
main.addListeners('login', loginCallbacks);
main.addListeners('logout', logoutCallbacks);
});