Files
SCM-Manager/scm-webapp/src/main/webapp/resources/js/sonia.scm.js

384 lines
9.9 KiB
JavaScript
Raw Normal View History

2010-11-03 18:40:43 +01:00
/**
2010-10-31 19:22:53 +01:00
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
2010-11-03 18:40:43 +01:00
*
2010-10-31 19:22:53 +01:00
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
2010-11-03 18:40:43 +01:00
*
2010-10-31 19:22:53 +01:00
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
2010-11-03 18:40:43 +01:00
*
2010-10-31 19:22:53 +01:00
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2010-11-03 18:40:43 +01:00
*
2010-10-31 19:22:53 +01:00
* http://bitbucket.org/sdorra/scm-manager
2010-11-03 18:40:43 +01:00
*
2010-09-04 16:36:25 +02:00
*/
2011-03-05 17:10:18 +01:00
Ext.ns("Sonia.scm");
2010-11-03 18:40:43 +01:00
2011-03-05 17:10:18 +01:00
Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
2010-09-04 16:36:25 +02:00
2011-03-05 17:10:18 +01:00
tabRepositoriesText: 'Repositories',
navChangePasswordText: 'Change Password',
sectionMainText: 'Main',
sectionSecurityText: 'Security',
navRepositoriesText: 'Repositories',
sectionConfigText: 'Config',
navGeneralConfigText: 'General',
tabGeneralConfigText: 'SCM Config',
2010-09-05 13:54:49 +02:00
2011-03-05 17:10:18 +01:00
navRepositoryTypesText: 'Repository Types',
tabRepositoryTypesText: 'Repository Config',
navPluginsText: 'Plugins',
tabPluginsText: 'Plugins',
navUsersText: 'Users',
tabUsersText: 'Users',
navGroupsText: 'Groups',
tabGroupsText: 'Groups',
2010-11-03 18:40:43 +01:00
2011-03-05 17:10:18 +01:00
sectionLoginText: 'Login',
navLoginText: 'Login',
sectionLogoutText: 'Log out',
navLogoutText: 'Log out',
2010-11-03 18:40:43 +01:00
logoutFailedText: 'Logout Failed!',
2011-03-06 13:45:27 +01:00
mainTabPanel: null,
constructor : function(config) {
2011-03-06 14:14:55 +01:00
this.addEvents('login', 'logout');
2011-03-06 13:45:27 +01:00
this.mainTabPanel = Ext.getCmp('mainTabPanel');
2011-03-06 14:14:55 +01:00
this.addListener('login', this.postLogin, this);
2011-03-06 13:45:27 +01:00
Sonia.scm.Main.superclass.constructor.call(this, config);
},
2011-03-06 14:14:55 +01:00
postLogin: function(){
this.createMainMenu();
this.createRepositoryPanel();
},
2011-03-05 17:10:18 +01:00
createRepositoryPanel: function(){
if ( debug ){
console.debug('create repository panel');
}
2011-03-06 13:45:27 +01:00
this.mainTabPanel.add({
2011-03-05 17:10:18 +01:00
id: 'repositories',
xtype: 'repositoryPanel',
title: this.tabRepositoriesText,
closeable: false,
autoScroll: true
});
2011-03-06 13:45:27 +01:00
this.mainTabPanel.setActiveTab('repositories');
2011-03-05 17:10:18 +01:00
},
2010-10-15 23:03:00 +02:00
2011-03-05 17:10:18 +01:00
createMainMenu: function(){
2010-11-03 18:40:43 +01:00
if ( debug ){
console.debug('create main menu');
}
var panel = Ext.getCmp('navigationPanel');
2010-11-25 19:08:32 +01:00
panel.addSection({
2010-12-06 17:15:27 +01:00
id: 'navMain',
2011-03-05 17:10:18 +01:00
title: this.sectionMainText,
2010-09-15 14:51:20 +02:00
items: [{
2011-03-05 17:10:18 +01:00
label: this.navRepositoriesText,
fn: function(){
2011-03-06 13:45:27 +01:00
this.mainTabPanel.setActiveTab('repositories');
2011-03-06 13:39:54 +01:00
},
scope: this
2010-09-15 14:18:55 +02:00
}]
2010-11-25 19:08:32 +01:00
});
2011-01-07 13:12:26 +01:00
var securitySection = null;
if ( state.user.type == 'xml' && state.user.name != 'anonymous' ){
securitySection = {
2011-03-05 17:10:18 +01:00
title: this.sectionSecurityText,
2011-01-07 13:12:26 +01:00
items: [{
2011-03-05 17:10:18 +01:00
label: this.navChangePasswordText,
2011-01-07 13:12:26 +01:00
fn: function(){
new Sonia.action.ChangePasswordWindow().show();
2011-03-05 17:10:18 +01:00
}
2011-01-07 13:12:26 +01:00
}]
}
}
2010-11-25 19:08:32 +01:00
if ( admin ){
2011-01-07 13:12:26 +01:00
2010-11-25 19:08:32 +01:00
panel.addSections([{
2010-12-06 17:15:27 +01:00
id: 'navConfig',
2011-03-05 17:10:18 +01:00
title: this.sectionConfigText,
2010-11-25 19:08:32 +01:00
items: [{
2011-03-05 17:10:18 +01:00
label: this.navGeneralConfigText,
2010-11-25 19:08:32 +01:00
fn: function(){
2011-03-06 13:39:54 +01:00
this.addTabPanel("scmConfig", "scmConfig", this.navGeneralConfigText);
},
scope: this
2010-11-25 19:08:32 +01:00
},{
2011-03-05 17:10:18 +01:00
label: this.navRepositoryTypesText,
2010-11-25 19:08:32 +01:00
fn: function(){
2011-03-06 13:39:54 +01:00
this.addTabPanel('repositoryConfig', 'repositoryConfig', this.tabRepositoryTypesText);
},
scope: this
},{
2011-03-05 17:10:18 +01:00
label: this.navPluginsText,
fn: function(){
2011-03-06 13:39:54 +01:00
this.addTabPanel('plugins', 'pluginGrid', this.navPluginsText);
},
scope: this
2010-11-25 19:08:32 +01:00
}]
}]);
2011-01-07 13:12:26 +01:00
if ( securitySection == null ){
securitySection = {
2011-03-05 17:10:18 +01:00
title: this.sectionSecurityText,
2011-01-07 13:12:26 +01:00
items: []
}
}
securitySection.items.push({
2011-03-05 17:10:18 +01:00
label: this.navUsersText,
2011-01-07 13:12:26 +01:00
fn: function(){
2011-03-06 13:39:54 +01:00
this.addTabPanel('users', 'userPanel', this.navUsersText);
},
scope: this
2011-01-07 13:12:26 +01:00
});
securitySection.items.push({
2011-03-05 17:10:18 +01:00
label: this.navGroupsText,
2011-01-07 13:12:26 +01:00
fn: function(){
2011-03-06 13:39:54 +01:00
this.addTabPanel('groups', 'groupPanel', this.tabGroupsText);
},
scope: this
2011-01-07 13:12:26 +01:00
});
}
if ( securitySection != null ){
panel.addSection( securitySection );
2010-11-25 19:08:32 +01:00
}
2010-12-30 13:44:40 +01:00
if ( state.user.name == 'anonymous' ){
panel.addSection({
id: 'navLogin',
2011-03-05 17:10:18 +01:00
title: this.sectionLoginText,
2010-12-30 13:44:40 +01:00
items: [{
2011-03-05 17:10:18 +01:00
label: this.sectionLoginText,
2011-03-06 13:39:54 +01:00
fn: this.login,
scope: this
2010-12-30 13:44:40 +01:00
}]
});
} else {
panel.addSection({
id: 'navLogout',
2011-03-05 17:10:18 +01:00
title: this.sectionLogoutText,
2010-12-30 13:44:40 +01:00
items: [{
2011-03-05 17:10:18 +01:00
label: this.navLogoutText,
2011-03-06 13:39:54 +01:00
fn: this.logout,
scope: this
2010-12-30 13:44:40 +01:00
}]
});
}
2010-11-25 19:08:32 +01:00
//fix hidden logout button
panel.doLayout();
2011-03-06 13:39:54 +01:00
},
addTabPanel: function(id, xtype, title){
2011-03-06 13:45:27 +01:00
var tab = this.mainTabPanel.findById( id );
2011-03-06 13:39:54 +01:00
if ( tab == null ){
2011-03-06 13:45:27 +01:00
this.mainTabPanel.add({
2011-03-06 13:39:54 +01:00
id: id,
xtype: xtype,
title: title,
closable: true,
autoScroll: true
});
}
2011-03-06 13:45:27 +01:00
this.mainTabPanel.setActiveTab(id);
2011-03-06 13:39:54 +01:00
},
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;
2011-03-06 13:39:54 +01:00
// call login callback functions
this.fireEvent("login", state);
2011-03-06 13:39:54 +01:00
this.execCallbacks(loginCallbacks, state);
},
clearState: function(){
// clear state
state = null;
// clear repository store
repositoryTypeStore.removeAll();
// remove all tabs
2011-03-06 13:45:27 +01:00
this.mainTabPanel.removeAll();
2011-03-06 13:39:54 +01:00
// 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);
this.fireEvent( "logout", state );
2011-03-06 13:39:54 +01:00
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(this.logoutFailedText);
2011-03-06 13:39:54 +01:00
}
});
2011-03-06 14:14:55 +01:00
},
addListeners: function(event, callbacks){
Ext.each(callbacks, function(callback){
if ( Ext.isFunction(callback) ){
this.addListener(event, callback);
} else if (Ext.isObject(callback)) {
2011-03-06 14:18:20 +01:00
this.addListener(event, callback.fn, callback.scope);
2011-03-06 14:14:55 +01:00
} else if (debug){
console.debug( "callback is not a function or object. " + callback );
}
2011-03-06 14:18:20 +01:00
}, this);
2010-09-05 16:14:46 +02:00
}
2011-03-05 17:10:18 +01:00
});
Ext.onReady(function(){
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var mainTabPanel = new Ext.TabPanel({
id: 'mainTabPanel',
region: 'center',
deferredRender: false
});
new Ext.Viewport({
layout: 'border',
items: [
new Ext.BoxComponent({
region: 'north',
id: 'north-panel',
contentEl: 'north',
height: 75
}), {
region: 'west',
id: 'navigationPanel',
title: 'Navigation',
xtype: 'navPanel',
split: true,
width: 200,
minSize: 175,
maxSize: 400,
collapsible: true,
margins: '0 0 0 5'
},
new Ext.BoxComponent({
region: 'south',
id: 'south-panel',
contentEl: 'south',
height: 16,
margins: '2 2 2 5'
}),
mainTabPanel
]
});
2011-03-06 13:39:54 +01:00
main = new Sonia.scm.Main();
main.checkLogin();
2011-03-05 17:10:18 +01:00
2011-03-06 13:45:27 +01:00
/**
* Adds a tab to main TabPanel
*
* @deprecated use main.addTabPanel
*/
2011-03-05 17:10:18 +01:00
function addTabPanel(id, xtype, title){
2011-03-06 13:45:27 +01:00
main.addTabPanel(id, xtype, title);
2010-11-03 18:40:43 +01:00
}
2011-03-06 14:14:55 +01:00
main.addListeners('login', loginCallbacks);
main.addListeners('logout', logoutCallbacks);
2010-09-04 16:36:25 +02:00
});