improve session and error handling, see #23

This commit is contained in:
Sebastian Sdorra
2011-05-31 19:32:30 +02:00
parent d015264cbf
commit c229e19ac8
8 changed files with 146 additions and 111 deletions

View File

@@ -491,7 +491,13 @@ if (Sonia.scm.Main){
sectionLogoutText: 'Abmelden',
navLogoutText: 'Abmelden',
logoutFailedText: 'Abmeldung Fehlgeschlagen!'
logoutFailedText: 'Abmeldung Fehlgeschlagen!',
errorTitle: 'Fehler',
errorMessage: 'Es ist ein unbekannter Fehler aufgetreten.',
errorSessionExpiredTitle: 'Session abgelaufen',
errorSessionExpiredMessage: 'Ihre Session ist abgelaufen. Bitte melden sie sich neu an.'
});
}

View File

@@ -270,15 +270,13 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
success: function(){
this.el.unmask();
},
failure: function(){
failure: function(result){
this.el.unmask();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.errorMsgText,
scope: this,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.errorMsgText
);
}
});
},
@@ -306,16 +304,14 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
clearTimeout(tid);
el.unmask();
},
failure: function(){
failure: function(result){
el.unmask();
clearTimeout(tid);
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.errorMsgText,
scope: this,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.errorMsgText
);
}
});
}
@@ -441,9 +437,13 @@ Sonia.config.SimpleConfigForm = Ext.extend(Sonia.config.ConfigForm,{
success: function(response){
this.el.unmask();
},
failure: function(){
failure: function(result){
this.el.unmask();
Ext.Msg.alert( this.failedText );
main.handleFailure(
result.status,
null,
this.failedText
);
}
});
},
@@ -461,10 +461,14 @@ Sonia.config.SimpleConfigForm = Ext.extend(Sonia.config.ConfigForm,{
clearTimeout(tid);
el.unmask();
},
failure: function(){
failure: function(result){
el.unmask();
clearTimeout(tid);
Ext.Msg.alert( this.failedText );
main.handleFailure(
result.status,
null,
this.failedText
);
}
});
}

View File

@@ -348,15 +348,14 @@ Sonia.group.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
el.unmask();
this.execCallback(this.onUpdate, group);
},
failure: function(){
failure: function(result){
clearTimeout(tid);
el.unmask();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.updateErrorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.updateErrorMsgText
);
}
});
},
@@ -388,15 +387,14 @@ Sonia.group.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
el.unmask();
this.execCallback(this.onCreate, item);
},
failure: function(){
failure: function(result){
clearTimeout(tid);
el.unmask();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.createErrorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.createErrorMsgText
);
}
});
},
@@ -494,13 +492,12 @@ Sonia.group.Panel = Ext.extend(Ext.Panel, {
this.reload();
this.resetPanel();
},
failure: function(){
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.errorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
failure: function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.errorMsgText
);
}
});
}

View File

@@ -97,17 +97,16 @@ Sonia.plugin.Center = Ext.extend(Ext.util.Observable, {
this.restartText);
this.fireEvents('installed', pluginId);
},
failure: function(){
failure: function(result){
if ( debug ){
console.debug('plugin installation failed');
}
loadingBox.hide();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.installFailedText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.installFailedText
);
}
});
},
@@ -132,17 +131,16 @@ Sonia.plugin.Center = Ext.extend(Ext.util.Observable, {
this.restartText);
this.fireEvents('uninstalled', pluginId);
},
failure: function(){
failure: function(result){
if ( debug ){
console.debug('plugin uninstallation failed');
}
loadingBox.hide();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.uninstallFailedText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.uninstallFailedText
);
}
});
},
@@ -168,17 +166,16 @@ Sonia.plugin.Center = Ext.extend(Ext.util.Observable, {
this.restartText);
this.fireEvents('updated', pluginId);
},
failure: function(){
failure: function(result){
if ( debug ){
console.debug('plugin update failed');
}
loadingBox.hide();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.updateFailedText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.updateFailedText
);
}
});
}

View File

@@ -439,16 +439,15 @@ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
el.unmask();
this.execCallback(this.onUpdate, item);
},
failure: function(){
failure: function(result){
this.fireEvent('updateFailed', item);
clearTimeout(tid);
el.unmask();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.updateErrorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.updateErrorMsgText
);
}
});
},
@@ -478,16 +477,15 @@ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
el.unmask();
this.execCallback(this.onCreate, item);
},
failure: function(){
failure: function(result){
this.fireEvent('creationFailed', item);
clearTimeout(tid);
el.unmask();
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.createErrorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
result.status,
this.errorTitleText,
this.createErrorMsgText
);
}
});
},
@@ -841,13 +839,12 @@ Sonia.repository.Panel = Ext.extend(Ext.Panel, {
this.reload();
this.resetPanel();
},
failure: function(){
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.errorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
failure: function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.errorMsgText
);
}
});
}

View File

@@ -50,12 +50,11 @@ Sonia.rest.JsonStore = Ext.extend( Ext.data.JsonStore, {
}
this.removeAll();
} else {
Ext.MessageBox.show({
title: this.errorTitleText,
msg: String.format( this.errorMsgText, status ),
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
main.handleFailure(
status,
this.errorTitleText,
this.errorMsgText
);
}
},
scope: this

View File

@@ -59,6 +59,12 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
logoutFailedText: 'Logout Failed!',
errorTitle: 'Error',
errorMessage: 'Unknown error occurred.',
errorSessionExpiredTitle: 'Session expired',
errorSessionExpiredMessage: 'Your session is expired. Please relogin.',
mainTabPanel: null,
infoPanels: [],
@@ -334,6 +340,38 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
console.debug( "callback is not a function or object. " + callback );
}
}, this);
},
handleFailure: function(status, title, message){
if (debug){
console.debug( 'handle failure for status code: ' + status );
}
if ( status == 401 ){
Ext.Msg.show({
title: this.errorSessionExpiredTitle,
msg: this.errorSessionExpiredMessage,
buttons: Ext.Msg.OKCANCEL,
fn: function(btn){
if ( btn == 'ok' ){
this.login();
}
},
scope: this
});
} else {
if ( title == null ){
title = this.errorTitle;
}
if ( message == null ){
message = this.errorMessage;
}
Ext.MessageBox.show({
title: title,
msg: String.format(message, status),
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
}
}
});

View File

@@ -264,13 +264,12 @@ Sonia.user.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
}
this.execCallback(this.onUpdate, item);
},
failure: function(){
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.updateErrorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
failure: function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.updateErrorMsgText
);
}
});
@@ -296,13 +295,12 @@ Sonia.user.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
this.getForm().reset();
this.execCallback(this.onCreate, user);
},
failure: function(){
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.createErrorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
failure: function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.createErrorMsgText
);
}
});
},
@@ -421,13 +419,12 @@ Sonia.user.Panel = Ext.extend(Ext.Panel, {
this.reload();
this.resetPanel();
},
failure: function(){
Ext.MessageBox.show({
title: this.errorTitleText,
msg: this.errorMsgText,
buttons: Ext.MessageBox.OK,
icon:Ext.MessageBox.ERROR
});
failure: function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.errorMsgText
);
}
});
}