From e15731070f8a31f9df5a98a6aa63433fab316d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Maur=C3=ADcio?= Date: Thu, 24 Apr 2014 13:03:55 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@1864 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../static/html/app/Form1/Form1Controller.js | 2 +- .../static/html/app/Form1/Form1View.html | 4 - .../static/html/app/Login/LoginController.js | 64 +++++++-- .../static/html/app/Login/LoginView.html | 4 +- .../static/html/app/Main/MainController.js | 127 +++++++++++++----- .../html/app/SearchForm/SearchController.js | 4 +- .../html/app/SearchForm/SearchView.html | 4 +- .../static/html/app/services/DataService.js | 70 +++++----- .../html/app/services/HttpInterceptor.js | 24 ++-- .../static/html/app/services/StaticData.js | 16 +++ .../static/html/app/services/Utils.js | 1 + .../WebContent/static/html/css/theme.css | 6 +- .../WebContent/static/html/index.html | 2 +- .../WebContent/static/html/views-all.html | 2 +- 14 files changed, 225 insertions(+), 105 deletions(-) create mode 100644 trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/StaticData.js diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js index 7fe11de5..d36d74ad 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js @@ -9,7 +9,7 @@ model: null, actions: { get: 'getFichaEAdmissaoInicial', - upsert: 'upsertFichaEAdmissaoInicial',//TODO: ??? + upsert: 'sendFichaEAdmissaoInicial',//TODO: ??? destroy: 'deleteFichaEAdmissaoInicial'//TODO: ??? } }); diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html index 0a2931f2..570aebe4 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html @@ -3714,10 +3714,6 @@ - - -
-

diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginController.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginController.js index 83b650d7..e537fb51 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginController.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginController.js @@ -2,25 +2,65 @@ { $scope.globals = globals; + $scope.storeLogin = new globals.dataService.store({ + model: null, + actions: { + upsert: 'doLogin' + } + }); + $scope.storeLogin.broadcastEvents = false; + + $scope.editing = { + user: 'admin', + pass: 'admin' + }; + //login procedure ---> user clicks the Login button - $scope.login = function(arg) { + $scope.login = function(arg) { - $scope.iaLoginMessages.message = 'Nome de Utilizador ou Palavra-Passe errados.'; - $scope.iaLoginMessages.cssClass = 'bg-danger'; - $scope.iaLoginMessages.show(); + $rootScope.$broadcast('loadingStatusActive'); - $timeout(function () { - - $scope.iaLoginMessages.hide(); + $scope.selected = {}; - $rootScope.$emit('onloginsuccessfull', {response: null}); + $scope.iaLoginMessages.hide(); - }, 0); - }; + $scope.storeLogin.upsert({}, $scope.editing, function(response, selected, editing, isNewRecord){ - $scope.$on('afterrender', function(event, args){ + $rootScope.$broadcast('loadingStatusInactive'); + if(response.success) + { + if($scope.$parent.sessionTimeout) + { + //go to previous module before timeout... + var className = $scope.$parent.beforeSessionTimeoutModule.ClassName; - }); + $scope.$parent.loadModule({Controller: className}, function(className, scope, isNewModule){ + + $scope.$parent.sessionTimeout = false; + $scope.$parent.beforeSessionTimeoutModule = null; + }); + } + else + { + $rootScope.$emit('onloginsuccessfull', {response: response}); + } + } + else + { + if(response.messages.length > 0) + { + var firstMessage = response.messages[0].messageData; + + $scope.iaLoginMessages.message = firstMessage; + $scope.iaLoginMessages.cssClass = 'bg-danger'; + $scope.iaLoginMessages.show(); + } + } + }); + }; + + $scope.$on('afterrender', function(event, args){ + }); }); \ No newline at end of file diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginView.html b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginView.html index 222bbeb8..b7e73ccd 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginView.html +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Login/LoginView.html @@ -21,11 +21,11 @@
- +
- +
diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Main/MainController.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Main/MainController.js index 6f0215c1..64e2558d 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Main/MainController.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Main/MainController.js @@ -2,6 +2,15 @@ { var me = this; + $scope.storeUserSession = new globals.dataService.store({ + model: null, + actions: { + get: 'checkLogin', + destroy: 'doLogout' + } + }); + $scope.storeUserSession.broadcastEvents = true; + //will contain all the application HTML $scope.viewCache = null; @@ -20,6 +29,10 @@ $scope.menuItems = []; + //if true, indicates a session timeout + $scope.sessionTimeout = false; + $scope.beforeSessionTimeoutModule = null; + //this div will contain all modules currently not in view var divTemp = $('
'); @@ -28,52 +41,47 @@ $scope.divMainPanel = $('body #main-panel'); - $scope.renderModule('body #main-panel', 'Login', null, true, function(className, scope){ - - $timeout(function() { - + $scope.storeUserSession.get(function(response, status, headers, config, items){ + + if(response.success) + { + //TODO: repeated code ??? $('#main-panel').show(); //globals.plugins.setDefaults(); //globals.plugins.setBootstrap(); $rootScope.$broadcast('loadingStatusInactive'); - }); - }); - - //$scope.buildTopMenu(); + $rootScope.$emit('onloginsuccessfull', {response: response}); + } + else + { + $scope.renderModule('body #main-panel', 'Login', null, true, function(className, scope){ - }; + $timeout(function() { - $rootScope.$on('onloginsuccessfull', function(event, args){ - - $scope.loadModule({Controller: 'Search'}, function(className, scope, isNewModule){ + //TODO: repeated code ??? + $('#main-panel').show(); - }); - - //$scope.renderModule('body #main-panel', 'Search', null, true, function(className, scope){ - - // $timeout(function() { - - // }); - //}); + //globals.plugins.setDefaults(); + //globals.plugins.setBootstrap(); - //var form1 = $scope.getModule('Form1'); + $rootScope.$broadcast('loadingStatusInactive'); + }); + }); + } + }); - ////load default module: Form1 - //$scope.renderModule('body #main-panel', 'Form1', null, true, function(className, scope){ - // $timeout(function() { + }; - // //$('#main-panel').show(); - - // //globals.plugins.setDefaults(); - // //globals.plugins.setBootstrap(); + $rootScope.$on('onloginsuccessfull', function(event, args){ - // //$rootScope.$broadcast('loadingStatusInactive'); - // }); - //}); + // go to the default module and/or landing page + $scope.loadModule({Controller: 'Search'}, function(className, scope, isNewModule){ + + }); }); //creates/renders a new controller+view into the given placeholder @@ -307,7 +315,7 @@ } } - $scope.currentModuleName = subModule.Name; + $scope.currentModuleName = subModule.Controller; }); }; @@ -365,6 +373,7 @@ } }; + // executes a logout from the application and perfomrs cleanup operations $scope.logout = function(){ globals.message.confirm({ @@ -373,9 +382,25 @@ if(result) { - $scope.loadModule({Controller: 'Login'}, function(className, scope, isNewModule){ + $scope.storeUserSession.broadcastEvents = false; + + $scope.storeUserSession.destroy(null, function(response){ - }); + $scope.storeUserSession.broadcastEvents = true; + + if(response.success) + { + //TODO: cleanup the whole application ??? + + $scope.loadModule({Controller: 'Login'}, function(className, scope, isNewModule){ + + }); + } + else + { + + } + }); } } }); @@ -405,9 +430,25 @@ $scope.notification = null; + $scope.defaultExceptionMessage = { + success: false, + data: null, + messages: [ + { + type: 'ERROR', + messageData: 'Ocorreu um erro de sistema.' + } + ] + }; + $rootScope.$on('response', function(event, args){ - var response = args.response; + var response = args.response, msgCss = 'default'; + + if(response.data == undefined || response.messages == undefined) + { + response = $scope.defaultExceptionMessage; + } if(response != undefined && response != null && response.messages.length > 0) { @@ -415,7 +456,7 @@ $scope.FirstMessage = response.messages[0]; - $scope.FirstMessage.type = globals.utils.getMessageTypeCSS($scope.FirstMessage.type); + msgCss = globals.utils.getMessageTypeCSS($scope.FirstMessage.type); $scope.MessageCount = response.messages.length; } @@ -430,7 +471,7 @@ text: $scope.FirstMessage.messageData, maxVisible: 1, template: - '
' + + '
' + '+{{MessageCount-1}}' + '' + '
' + @@ -462,6 +503,18 @@ //$scope.windowViewServerResponse.viewController.list($scope.ServerResponse); }; + $rootScope.$on('onsessiontimeout', function(event, args){ + + var eee = args.response; + + $scope.sessionTimeout = true; + $scope.beforeSessionTimeoutModule = $scope.currentModule; + + $scope.loadModule({Controller: 'Login'}, function(className, scope, isNewModule){ + + }); + }); + //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ //fires whenever a new module is rendered, if broadcastCreation is true on method renderModule diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchController.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchController.js index 614ce6d2..fa08fbb9 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchController.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchController.js @@ -66,8 +66,8 @@ $scope.onEmpresaChange = function(selectedValue, selectedRecord){ $scope.comboEstabelecimentos.store.extraParams = { - empresaID: selectedRecord.id, - filter: 'sede' + id: selectedRecord.id, + filter: selectedRecord.designacao_social }; $scope.comboEstabelecimentos.loadStore(function(response, status, headers, config, items){ diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchView.html b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchView.html index 880bfd91..2971c3fb 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchView.html +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/SearchForm/SearchView.html @@ -46,7 +46,7 @@ store-model="" store-actions-get="getEstabelecimentos" value-field="id" - display-field="designacao_social" + display-field="nome" add-empty-option="false" on-change="onEstabelecimentoChange(selectedValue, selectedRecord)"> @@ -63,7 +63,7 @@ store-model="" store-actions-get="getTrabalhadores" value-field="id" - display-field="designacao_social" + display-field="nome" add-empty-option="false" on-change="onTrabalhadorChange(selectedValue, selectedRecord)"> diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/DataService.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/DataService.js index afeedc00..29d5b988 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/DataService.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/DataService.js @@ -33,6 +33,8 @@ this.convertToModel = true; this.broadcastEvents = true; + $http.defaults.withCredentials = true; + this.get = function(){ var callbackFn = arguments[0]; @@ -82,6 +84,11 @@ }). error(function(response, status, headers, config) { + if(me.broadcastEvents) + { + $rootScope.$broadcast('response', {response: response}); + } + callback(callbackFn, [response, status, headers, config]); }); @@ -114,45 +121,40 @@ }). success(function(response, status, headers, config) { - $rootScope.$broadcast('response', {response: response}); + if(me.broadcastEvents) + { + $rootScope.$broadcast('response', {response: response}); + } if(response.success) { - // var idPropertyValue = editing[modelInstance.idProperty], - // isNewRecord = (idPropertyValue == 0 || idPropertyValue == null || idPropertyValue == undefined); + // var idPropertyValue = editing[modelInstance.idProperty], + // isNewRecord = (idPropertyValue == 0 || idPropertyValue == null || idPropertyValue == undefined); - // if(response.data != null) - // { - // if(angular.isArray(response.data)) - // { - // response.data = modelService.toModel(me.model, response.data[0], null); - // } - // else - // { - // response.data = modelService.toModel(me.model, response.data, null); - // } - - // angular.copy(response.data, editing); - // angular.copy(response.data, selected); - // } + // if(response.data != null) + // { + // if(angular.isArray(response.data)) + // { + // response.data = modelService.toModel(me.model, response.data[0], null); + // } + // else + // { + // response.data = modelService.toModel(me.model, response.data, null); + // } + + // angular.copy(response.data, editing); + // angular.copy(response.data, selected); + // } } callback(callbackFn, [response, selected, editing, isNewRecord]); }). error(function(response, status, headers, config) { - var res = { - success: false, - data: null, - messages: [ - { - type: 'ERROR', - messageData: 'Ocorreu um erro de sistema.' - } - ] - }; - - $rootScope.$broadcast('response', {response: res}); + if(me.broadcastEvents) + { + $rootScope.$broadcast('response', {response: response}); + } callback(callbackFn, [response, selected, editing, isNewRecord]); }); @@ -182,12 +184,20 @@ }). success(function(response, status, headers, config) { - $rootScope.$broadcast('response', {response: response}); + if(me.broadcastEvents) + { + $rootScope.$broadcast('response', {response: response}); + } callback(callbackFn, [response]); }). error(function(response, status, headers, config) { + if(me.broadcastEvents) + { + $rootScope.$broadcast('response', {response: response}); + } + callback(callbackFn, [response]); }); }; diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/HttpInterceptor.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/HttpInterceptor.js index 32ae7246..e3b273fc 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/HttpInterceptor.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/HttpInterceptor.js @@ -17,19 +17,19 @@ evoapp.factory('httpInterceptor', function ($rootScope, $q){ var ended = function(response){ - //intercept SECURITYEXCEPTION responses - //if(!response.data.success && response.data.response) - //{ - // if(response.data.response.ServerResponse.length > 0) - // { - // var sr = response.data.response.ServerResponse[0]; + //intercept exceptions + if(response.data.success != undefined) + { + if(response.data.messages.length > 0) + { + var firstMessage = response.data.messages[0]; - // if(sr.MessageType == 'SECURITYEXCEPTION') - // { - // $rootScope.$broadcast('response', {response: response.data}); - // } - // } - //} + if(firstMessage.type == 'SESSIONTIMEOUT') + { + $rootScope.$broadcast('onsessiontimeout', {response: response.data}); + } + } + } activeRequests--; diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/StaticData.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/StaticData.js new file mode 100644 index 00000000..8a07c984 --- /dev/null +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/StaticData.js @@ -0,0 +1,16 @@ + evoapp.factory('staticData', function($rootScope) { + + //exceptions + var exceptions = { + ERROR: 'ERROR', + SECURITYEXCEPTION: 'SECURITYEXCEPTION', + SESSIONTIMEOUT: 'SESSIONTIMEOUT', + INFO: 'INFO', + QUESTION: 'QUESTION', + WARNING: 'WARNING' + }; + + return { + exceptions: exceptions + }; +}); \ No newline at end of file diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/Utils.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/Utils.js index 2e4f4d50..7ab8ffcb 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/Utils.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/services/Utils.js @@ -15,6 +15,7 @@ { case 'ERROR': case 'SECURITYEXCEPTION': + case 'SESSIONTIMEOUT': messageType = 'danger'; break; diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/css/theme.css b/trunk/SiprpWebFichasClinicas/WebContent/static/html/css/theme.css index cb98d4c0..7d0dc77f 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/css/theme.css +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/css/theme.css @@ -258,4 +258,8 @@ body.modal-open { overflow: auto; } - +.modal-backdrop, .modal-backdrop.fade.in { + opacity: 0.7; + filter: alpha(opacity=70); + background: transparent!important; +} diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html b/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html index b4446d33..8a4a8cab 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html @@ -109,7 +109,7 @@
- +