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

@@ -38,10 +38,18 @@ var admin = false;
// sonia.scm.api.rest.resources.UserResource.DUMMY_PASSWORT // sonia.scm.api.rest.resources.UserResource.DUMMY_PASSWORT
var dummyPassword = '__dummypassword__'; var dummyPassword = '__dummypassword__';
// functions called after login /**
* functions called after login
*
* @deprecated use main.addListener('login', fn, scope)
*/
var loginCallbacks = []; var loginCallbacks = [];
// function called after logout /**
* functions called after logout
*
* @deprecated use main.addListener('logout', fn, scope)
*/
var logoutCallbacks = []; var logoutCallbacks = [];
var restUrl = "api/rest/"; var restUrl = "api/rest/";

View File

@@ -62,11 +62,17 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
mainTabPanel: null, mainTabPanel: null,
constructor : function(config) { constructor : function(config) {
this.addEvents("login", "logout"); this.addEvents('login', 'logout');
this.mainTabPanel = Ext.getCmp('mainTabPanel'); this.mainTabPanel = Ext.getCmp('mainTabPanel');
this.addListener('login', this.postLogin, this);
Sonia.scm.Main.superclass.constructor.call(this, config); Sonia.scm.Main.superclass.constructor.call(this, config);
}, },
postLogin: function(){
this.createMainMenu();
this.createRepositoryPanel();
},
createRepositoryPanel: function(){ createRepositoryPanel: function(){
if ( debug ){ if ( debug ){
console.debug('create repository panel'); console.debug('create repository panel');
@@ -303,6 +309,18 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
Ext.Msg.alert(this.logoutFailedText); 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); main.addTabPanel(id, xtype, title);
} }
// register login callbacks main.addListeners('login', loginCallbacks);
main.addListeners('logout', logoutCallbacks);
// create menu
loginCallbacks.splice(0, 0, {fn: main.createMainMenu, scope: main});
// add repository tab
loginCallbacks.push({fn: main.createRepositoryPanel, scope: main});
}); });