improve Sonia.scm.Main

This commit is contained in:
Sebastian Sdorra
2011-03-06 13:39:54 +01:00
parent d3eb4d9425
commit ed9c7d6c3d
3 changed files with 140 additions and 112 deletions

View File

@@ -46,100 +46,6 @@ var logoutCallbacks = [];
var restUrl = "api/rest/"; var restUrl = "api/rest/";
function execCallbacks(callbacks, param){
Ext.each(callbacks, function(callback){
if ( Ext.isFunction(callback) ){
callback(state);
} else if (Ext.isObject(callback)) {
callback.fn.call( callback.scope, param );
} else if (debug){
console.debug( "callback is not a function or object. " + callback );
}
});
}
function loadState(s){
if ( debug ){
console.debug( s );
}
state = s;
admin = s.user.admin;
// call login callback functions
execCallbacks(loginCallbacks, state);
}
function clearState(){
// clear state
state = null;
// clear repository store
repositoryTypeStore.removeAll();
// remove all tabs
Ext.getCmp('mainTabPanel').removeAll();
// remove navigation items
Ext.getCmp('navigationPanel').removeAll();
}
function checkLogin(){
Ext.Ajax.request({
url: restUrl + 'authentication.json',
method: 'GET',
success: function(response){
if ( debug ){
console.debug('login success');
}
var s = Ext.decode(response.responseText);
loadState(s);
},
failure: function(){
if ( debug ){
console.debug('login failed');
}
var loginWin = new Sonia.login.Window();
loginWin.show();
}
});
}
function login(){
clearState();
var loginWin = new Sonia.login.Window();
loginWin.show();
}
function logout(){
Ext.Ajax.request({
url: restUrl + 'authentication/logout.json',
method: 'GET',
success: function(response){
if ( debug ){
console.debug('logout success');
}
clearState();
// call logout callback functions
execCallbacks(logoutCallbacks, state);
var s = null;
var text = response.responseText;
if ( text != null && text.length > 0 ){
s = Ext.decode( text );
}
if ( s != null && s.success ){
loadState(s);
} else {
// show login window
var loginWin = new Sonia.login.Window();
loginWin.show();
}
},
failure: function(){
if ( debug ){
console.debug('logout failed');
}
Ext.Msg.alert('Logout Failed!');
}
});
}
var userSearchStore = new Ext.data.JsonStore({ var userSearchStore = new Ext.data.JsonStore({
root: 'results', root: 'results',
idProperty: 'value', idProperty: 'value',
@@ -160,5 +66,8 @@ var groupSearchStore = new Ext.data.JsonStore({
}) })
}); });
// the main object (sonia.scm)
var main = null;
// enable extjs quicktips // enable extjs quicktips
Ext.QuickTips.init(); Ext.QuickTips.init();

View File

@@ -114,7 +114,7 @@ Sonia.login.Form = Ext.extend(Ext.FormPanel,{
if ( debug ){ if ( debug ){
console.debug( 'login success' ); console.debug( 'login success' );
} }
loadState( action.result ); main.loadState( action.result );
}, },
failure: function(form){ failure: function(form){

View File

@@ -84,8 +84,9 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
items: [{ items: [{
label: this.navRepositoriesText, label: this.navRepositoriesText,
fn: function(){ fn: function(){
mainTabPanel.setActiveTab('repositories'); Ext.getCmp('mainTabPanel').setActiveTab('repositories');
} },
scope: this
}] }]
}); });
@@ -111,18 +112,21 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
items: [{ items: [{
label: this.navGeneralConfigText, label: this.navGeneralConfigText,
fn: function(){ fn: function(){
addTabPanel("scmConfig", "scmConfig", this.navGeneralConfigText); this.addTabPanel("scmConfig", "scmConfig", this.navGeneralConfigText);
} },
scope: this
},{ },{
label: this.navRepositoryTypesText, label: this.navRepositoryTypesText,
fn: function(){ fn: function(){
addTabPanel('repositoryConfig', 'repositoryConfig', this.tabRepositoryTypesText); this.addTabPanel('repositoryConfig', 'repositoryConfig', this.tabRepositoryTypesText);
} },
scope: this
},{ },{
label: this.navPluginsText, label: this.navPluginsText,
fn: function(){ fn: function(){
addTabPanel('plugins', 'pluginGrid', this.navPluginsText); this.addTabPanel('plugins', 'pluginGrid', this.navPluginsText);
} },
scope: this
}] }]
}]); }]);
@@ -136,14 +140,16 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
securitySection.items.push({ securitySection.items.push({
label: this.navUsersText, label: this.navUsersText,
fn: function(){ fn: function(){
addTabPanel('users', 'userPanel', this.navUsersText); this.addTabPanel('users', 'userPanel', this.navUsersText);
} },
scope: this
}); });
securitySection.items.push({ securitySection.items.push({
label: this.navGroupsText, label: this.navGroupsText,
fn: function(){ fn: function(){
addTabPanel('groups', 'groupPanel', this.tabGroupsText); this.addTabPanel('groups', 'groupPanel', this.tabGroupsText);
} },
scope: this
}); });
} }
@@ -157,7 +163,8 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
title: this.sectionLoginText, title: this.sectionLoginText,
items: [{ items: [{
label: this.sectionLoginText, label: this.sectionLoginText,
fn: login fn: this.login,
scope: this
}] }]
}); });
} else { } else {
@@ -166,13 +173,126 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
title: this.sectionLogoutText, title: this.sectionLogoutText,
items: [{ items: [{
label: this.navLogoutText, label: this.navLogoutText,
fn: logout fn: this.logout,
scope: this
}] }]
}); });
} }
//fix hidden logout button //fix hidden logout button
panel.doLayout(); panel.doLayout();
},
addTabPanel: function(id, xtype, title){
var mainTabPanel = Ext.getCmp('mainTabPanel');
var tab = mainTabPanel.findById( id );
if ( tab == null ){
mainTabPanel.add({
id: id,
xtype: xtype,
title: title,
closable: true,
autoScroll: true
});
}
mainTabPanel.setActiveTab(id);
},
execCallbacks: function(callbacks, param){
Ext.each(callbacks, function(callback){
if ( Ext.isFunction(callback) ){
callback(state);
} else if (Ext.isObject(callback)) {
callback.fn.call( callback.scope, param );
} else if (debug){
console.debug( "callback is not a function or object. " + callback );
}
});
},
loadState: function(s){
if ( debug ){
console.debug( s );
}
state = s;
admin = s.user.admin;
// call login callback functions
this.execCallbacks(loginCallbacks, state);
},
clearState: function(){
// clear state
state = null;
// clear repository store
repositoryTypeStore.removeAll();
// remove all tabs
Ext.getCmp('mainTabPanel').removeAll();
// remove navigation items
Ext.getCmp('navigationPanel').removeAll();
},
checkLogin: function(){
Ext.Ajax.request({
url: restUrl + 'authentication.json',
method: 'GET',
scope: this,
success: function(response){
if ( debug ){
console.debug('login success');
}
var s = Ext.decode(response.responseText);
this.loadState(s);
},
failure: function(){
if ( debug ){
console.debug('login failed');
}
var loginWin = new Sonia.login.Window();
loginWin.show();
}
});
},
login: function(){
this.clearState();
var loginWin = new Sonia.login.Window();
loginWin.show();
},
logout: function(){
Ext.Ajax.request({
url: restUrl + 'authentication/logout.json',
method: 'GET',
scope: this,
success: function(response){
if ( debug ){
console.debug('logout success');
}
this.clearState();
// call logout callback functions
this.execCallbacks(logoutCallbacks, state);
var s = null;
var text = response.responseText;
if ( text != null && text.length > 0 ){
s = Ext.decode( text );
}
if ( s != null && s.success ){
this.loadState(s);
} else {
// show login window
var loginWin = new Sonia.login.Window();
loginWin.show();
}
},
failure: function(){
if ( debug ){
console.debug('logout failed');
}
Ext.Msg.alert('Logout Failed!');
}
});
} }
}); });
@@ -218,7 +338,8 @@ Ext.onReady(function(){
] ]
}); });
checkLogin(); main = new Sonia.scm.Main();
main.checkLogin();
// adds a tab to main TabPanel // adds a tab to main TabPanel
function addTabPanel(id, xtype, title){ function addTabPanel(id, xtype, title){
@@ -237,8 +358,6 @@ Ext.onReady(function(){
// register login callbacks // register login callbacks
var main = new Sonia.scm.Main();
// create menu // create menu
loginCallbacks.splice(0, 0, {fn: main.createMainMenu, scope: main}); loginCallbacks.splice(0, 0, {fn: main.createMainMenu, scope: main});
// add repository tab // add repository tab