handle history for main navigation

This commit is contained in:
Sebastian Sdorra
2011-08-15 11:28:14 +02:00
parent 1c4426d629
commit 8763f0392d
2 changed files with 80 additions and 29 deletions

View File

@@ -49,21 +49,31 @@ Sonia.History = {
} }
}, },
register: function(id, fn){ register: function(id, fn, scope){
this.historyElements.push({ if (scope){
'id': id, this.historyElements[id] = {
'fn': fn 'fn': fn,
}); 'scope': scope
};
} else {
this.historyElements[id] = fn;
}
}, },
handleChange: function(id, params){ handleChange: function(id, params){
if ( debug ){ var el = this.historyElements[id];
console.debug( 'handle ' + id + ' with "' + params + '"' ); if (el){
} if (debug){
for (var i=0; i<this.historyElements.length; i++){ console.debug('handle history event for ' + id + ' with "' + params + '"');
if (this.historyElements.id == id){
el.fn(params);
} }
if (Ext.isFunction(el) ){
el();
} else {
el.fn.call(el.scope, params);
}
} else if (debug){
console.debug('could not find history element for ' + id);
} }
} }

View File

@@ -75,6 +75,7 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
this.addEvents('login', 'logout', 'init'); this.addEvents('login', 'logout', 'init');
this.mainTabPanel = Ext.getCmp('mainTabPanel'); this.mainTabPanel = Ext.getCmp('mainTabPanel');
this.addListener('login', this.postLogin, this); this.addListener('login', this.postLogin, this);
this.createHistory();
Sonia.scm.Main.superclass.constructor.call(this, config); Sonia.scm.Main.superclass.constructor.call(this, config);
}, },
@@ -118,6 +119,58 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
this.mainTabPanel.setActiveTab('repositories'); this.mainTabPanel.setActiveTab('repositories');
}, },
addRepositoriesTabPanel: function(){
this.mainTabPanel.setActiveTab('repositories');
},
addScmConfigTabPanel: function(){
if (admin){
this.addTabPanel("scmConfig", "scmConfig", this.navGeneralConfigText);
}
},
addRepositoryConfigTabPanel: function(){
if (admin){
this.addTabPanel('repositoryConfig', 'repositoryConfig', this.tabRepositoryTypesText);
}
},
addPluginTabPanel: function(){
if (admin){
this.addTabPanel('plugins', 'pluginGrid', this.navPluginsText);
}
},
addUsersTabPanel: function(){
if (admin){
this.addTabPanel('users', 'userPanel', this.navUsersText);
}
},
addGroupsTabPanel: function(){
if (admin){
this.addTabPanel('groups', 'groupPanel', this.tabGroupsText);
}
},
createHistory: function(){
Sonia.History.register('repositories', function(params){
this.addRepositoriesTabPanel();
// todo handle params
}, this);
Sonia.History.register('scmConfig', this.addScmConfigTabPanel, this);
Sonia.History.register('repositoryConfig', this.addRepositoryConfigTabPanel, this);
Sonia.History.register('plugins', this.addPluginTabPanel, this);
Sonia.History.register('users', function(params){
this.addUsersTabPanel();
// todo handle params
}, this);
Sonia.History.register('groups', function(params){
this.addUsersTabPanel();
// todo handle params
}, this);
},
createMainMenu: function(){ createMainMenu: function(){
if ( debug ){ if ( debug ){
console.debug('create main menu'); console.debug('create main menu');
@@ -128,9 +181,7 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
title: this.sectionMainText, title: this.sectionMainText,
links: [{ links: [{
label: this.navRepositoriesText, label: this.navRepositoriesText,
fn: function(){ fn: this.addRepositoriesTabPanel,
this.mainTabPanel.setActiveTab('repositories');
},
scope: this scope: this
}] }]
}); });
@@ -156,21 +207,15 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
title: this.sectionConfigText, title: this.sectionConfigText,
links: [{ links: [{
label: this.navGeneralConfigText, label: this.navGeneralConfigText,
fn: function(){ fn: this.addScmConfigTabPanel,
this.addTabPanel("scmConfig", "scmConfig", this.navGeneralConfigText);
},
scope: this scope: this
},{ },{
label: this.navRepositoryTypesText, label: this.navRepositoryTypesText,
fn: function(){ fn: this.addRepositoryConfigTabPanel,
this.addTabPanel('repositoryConfig', 'repositoryConfig', this.tabRepositoryTypesText);
},
scope: this scope: this
},{ },{
label: this.navPluginsText, label: this.navPluginsText,
fn: function(){ fn: this.addPluginTabPanel,
this.addTabPanel('plugins', 'pluginGrid', this.navPluginsText);
},
scope: this scope: this
}] }]
}]); }]);
@@ -184,16 +229,12 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
securitySection.links.push({ securitySection.links.push({
label: this.navUsersText, label: this.navUsersText,
fn: function(){ fn: this.addUsersTabPanel,
this.addTabPanel('users', 'userPanel', this.navUsersText);
},
scope: this scope: this
}); });
securitySection.links.push({ securitySection.links.push({
label: this.navGroupsText, label: this.navGroupsText,
fn: function(){ fn: this.addGroupsTabPanel,
this.addTabPanel('groups', 'groupPanel', this.tabGroupsText);
},
scope: this scope: this
}); });
} }