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

100 lines
3.1 KiB
JavaScript
Raw Normal View History

2010-11-03 18:40:43 +01:00
/**
2010-11-05 15:20:56 +01:00
* Copyright (c) 2010, Sebastian Sdorra
2010-10-31 19:22:53 +01:00
* 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
*/
2010-11-13 13:36:04 +01:00
// enable debug mode, if console is available
2010-11-13 14:08:55 +01:00
var debug = typeof console != 'undefined';
2010-11-03 18:40:43 +01:00
2010-09-06 14:34:04 +02:00
var state = null;
2010-11-25 19:08:32 +01:00
var admin = false;
2010-09-17 15:13:53 +02:00
2010-11-13 11:54:51 +01:00
// sonia.scm.api.rest.resources.UserResource.DUMMY_PASSWORT
var dummyPassword = '__dummypassword__';
2010-09-17 15:13:53 +02:00
// functions called after login
2010-11-03 18:40:43 +01:00
var loginCallbacks = [];
2010-09-17 15:13:53 +02:00
2010-11-03 18:40:43 +01:00
// function called after logout
var logoutCallbacks = [];
2010-09-17 15:31:19 +02:00
2010-09-09 18:35:54 +02:00
var restUrl = "api/rest/";
function loadState(s){
2010-11-03 18:40:43 +01:00
if ( debug ){
console.debug( s );
}
2010-09-09 18:35:54 +02:00
state = s;
2010-11-25 19:08:32 +01:00
admin = s.user.admin;
2010-11-03 18:40:43 +01:00
// call login callback functions
Ext.each(loginCallbacks, function(callback){
2010-09-09 18:35:54 +02:00
if ( Ext.isFunction(callback) ){
callback(state);
}
});
2010-09-17 15:13:53 +02:00
}
2010-11-03 18:40:43 +01:00
function logout(){
Ext.Ajax.request({
url: restUrl + 'authentication/logout.json',
method: 'GET',
success: function(){
if ( debug ){
console.debug('logout success');
}
// clear state
state = null;
// clear repository store
repositoryTypeStore.removeAll();
// remove all tabs
Ext.getCmp('mainTabPanel').removeAll();
// remove navigation items
Ext.getCmp('navigationPanel').removeAll();
// call logout callback functions
Ext.each(logoutCallbacks, function(callback){
if ( Ext.isFunction(callback) ){
callback(state);
}
});
// show login window
var loginWin = new Sonia.login.Window();
loginWin.show();
},
failure: function(){
if ( debug ){
console.debug('logout failed');
}
Ext.Msg.alert('Logout Failed!');
}
});
}
2010-11-13 11:12:14 +01:00
2010-11-13 11:54:51 +01:00
// enable extjs quicktips
Ext.QuickTips.init();