From c229e19ac854c4219064f957d3a99908b7a06e7c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 31 May 2011 19:32:30 +0200 Subject: [PATCH] improve session and error handling, see #23 --- .../src/main/webapp/resources/js/i18n/de.js | 8 +++- .../main/webapp/resources/js/sonia.config.js | 44 ++++++++++--------- .../main/webapp/resources/js/sonia.group.js | 39 ++++++++-------- .../main/webapp/resources/js/sonia.plugin.js | 39 ++++++++-------- .../webapp/resources/js/sonia.repository.js | 39 ++++++++-------- .../main/webapp/resources/js/sonia.rest.js | 11 +++-- .../src/main/webapp/resources/js/sonia.scm.js | 38 ++++++++++++++++ .../main/webapp/resources/js/sonia.user.js | 39 ++++++++-------- 8 files changed, 146 insertions(+), 111 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/i18n/de.js b/scm-webapp/src/main/webapp/resources/js/i18n/de.js index 2ba3b700ed..0a0caf3058 100644 --- a/scm-webapp/src/main/webapp/resources/js/i18n/de.js +++ b/scm-webapp/src/main/webapp/resources/js/i18n/de.js @@ -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.' }); } diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.config.js b/scm-webapp/src/main/webapp/resources/js/sonia.config.js index 054803fdb8..8c89017335 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.config.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.config.js @@ -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 + ); } }); } diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.group.js b/scm-webapp/src/main/webapp/resources/js/sonia.group.js index d3e081e747..c1b9e26c01 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.group.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.group.js @@ -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 + ); } }); } diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js b/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js index 3fe08d2ec5..af1f8e8a68 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js @@ -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 + ); } }); } diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.repository.js b/scm-webapp/src/main/webapp/resources/js/sonia.repository.js index 5ef2dfdd77..f5fd215d5e 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.repository.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.repository.js @@ -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 + ); } }); } diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.rest.js b/scm-webapp/src/main/webapp/resources/js/sonia.rest.js index f873b48b4c..003067bfbd 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.rest.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.rest.js @@ -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 diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js index 92822f48ac..660a8eee49 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js @@ -58,6 +58,12 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, { navLogoutText: 'Log out', logoutFailedText: 'Logout Failed!', + + errorTitle: 'Error', + errorMessage: 'Unknown error occurred.', + + errorSessionExpiredTitle: 'Session expired', + errorSessionExpiredMessage: 'Your session is expired. Please relogin.', mainTabPanel: null, @@ -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 + }); + } } }); diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.user.js b/scm-webapp/src/main/webapp/resources/js/sonia.user.js index 738839d9b9..cbbf1fe530 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.user.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.user.js @@ -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 + ); } }); }