This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit 56ceaf71cb0a7c0ded15ce9a98c3a205ad16134e Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue Jun 24 12:00:16 2014 +0200 use controller for alert --- pollen-ui-angular/src/main/webapp/i18n/fr.js | 2 + pollen-ui-angular/src/main/webapp/index.html | 5 ++ pollen-ui-angular/src/main/webapp/js/app.js | 20 ++++---- .../src/main/webapp/js/controllers/alertCtrl.js | 56 ++++++++++++++++++++++ .../src/main/webapp/js/controllers/pollCtrl.js | 56 +++++++++++----------- .../src/main/webapp/js/controllers/userCtrl.js | 32 ++++++++++--- pollen-ui-angular/src/main/webapp/js/services.js | 18 +++++++ .../src/main/webapp/partials/poll.html | 4 -- .../src/main/webapp/partials/user-edit.html | 2 - .../main/webapp/partials/user-lostPassword.html | 2 - .../src/main/webapp/partials/user-register.html | 4 +- 11 files changed, 146 insertions(+), 55 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/i18n/fr.js b/pollen-ui-angular/src/main/webapp/i18n/fr.js index 9466e8e..e624020 100644 --- a/pollen-ui-angular/src/main/webapp/i18n/fr.js +++ b/pollen-ui-angular/src/main/webapp/i18n/fr.js @@ -33,6 +33,8 @@ var translateFR = { 'user.error.mail.notFound' : 'Courriel n\'a pas été trouvé', 'user.error.mail.empty' : 'Courriel ne peux pas être vide', 'user.error.login' : 'Erreur sur le nom d\'utilisateur ou le mot de passe', +'user.error.login.mandatory' : 'Accès refusé, vous devez êtes connecté(e)', +'user.error.logout.mandatory' : 'Accès refusé, vous êtes connecté(e)', 'poll.tab.vote' : 'Voter', 'poll.tab.comment' : 'Commenter', diff --git a/pollen-ui-angular/src/main/webapp/index.html b/pollen-ui-angular/src/main/webapp/index.html index a4589d9..894c59e 100644 --- a/pollen-ui-angular/src/main/webapp/index.html +++ b/pollen-ui-angular/src/main/webapp/index.html @@ -51,6 +51,7 @@ <script src="js/controllers/userCtrl.js"></script> <script src="js/controllers/favoriteListCtrl.js"></script> <script src="js/controllers/localeCtrl.js"></script> + <script src="js/controllers/alertCtrl.js"></script> <script src="i18n/fr.js"></script> <script src="i18n/en.js"></script> @@ -148,6 +149,10 @@ </div> </nav> +<div class="pool-alert alert-float" ng-controller="printAlertCtrl" > + <alert ng-repeat="alert in data.alerts track by $index" type="{{alert.type}}" class="fakeLink" close="hideAlert(alert)" ng-click="hideAlert(alert)"> {{ alert.msg | translate }} </alert> +</div> + <div ng-view class='container' id="content"></div> </body> diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index 0465c9e..5d87bae 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'ui.bootstrap', 'pascalprecht.translate', 'ngAnimate']) +angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'alertControllers', 'ui.bootstrap', 'pascalprecht.translate', 'ngAnimate']) .config(['$httpProvider', function($httpProvider) { // edit header for locale and sessionToken $httpProvider.interceptors.push('httpInterceptor'); @@ -237,14 +237,16 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC scope.oldVal = {}; scope.change = false; scope.timeout; - scope.oldVal[attrs.ngModel] = scope.$eval(attrs.ngModel); - scope.$watch(attrs.ngModel, function (newVal, oldVal) { - if (newVal != scope.oldVal[attrs.ngModel]) { - scope.change = true; - } else { - scope.change = false; - } - }, true); + $timeout(function () { + scope.oldVal[attrs.ngModel] = scope.$eval(attrs.ngModel); + scope.$watch(attrs.ngModel, function (newVal, oldVal) { + if (angular.isDefined(oldVal) && newVal != scope.oldVal[attrs.ngModel]) { + scope.change = true; + } else { + scope.change = false; + } + }, true); + }, 500); var save = function () { if (scope.change) { diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js new file mode 100644 index 0000000..7d798c0 --- /dev/null +++ b/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js @@ -0,0 +1,56 @@ +/* + * #%L + * Pollen :: UI (Angular) + * %% + * Copyright (C) 2009 - 2014 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +angular.module('alertControllers', []) +.controller('printAlertCtrl', ['$scope', '$timeout', + function ($scope, $timeout) { + + if (angular.isUndefined($scope.data)) { + $scope.data = {} + } + $scope.data.alerts = []; + + $scope.$on('newError', function (event, error, timeout) { + var alert = {msg:error, type:'danger'}; + addAlert(alert, timeout); + }); + + $scope.$on('newSuccess', function (event, success, timeout) { + var alert = {msg:success, type:'success'}; + addAlert(alert, timeout); + }); + + var addAlert = function (alert, timeout) { + $scope.data.alerts.push(alert); + if (angular.isDefined(timeout)) { + $timeout(function () { + $scope.hideAlert(alert) + }, timeout); + } + } + + $scope.hideAlert = function (alert) { + var index = $scope.data.alerts.indexOf(alert); + if (index >= 0) { + $scope.data.alerts.splice(index, 1); + } + } +}]) \ No newline at end of file diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js index 316add0..ba0865e 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -54,14 +54,7 @@ angular.module('pollControllers', []) if (angular.isUndefined($scope.globalVariables)) { - $scope.globalVariables = {saved : SessionStorage.get().saved}; - SessionStorage.remove('saved'); - - $scope.$watch('globalVariables.saved', function() { - $timeout(function () { - $scope.globalVariables.saved = false; - }, 5000); - }); + $scope.globalVariables = {}; /** * Sauvegarde du token si non connecté @@ -327,8 +320,8 @@ angular.module('pollControllers', []) } }]) -.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', 'SessionStorage', 'PollVoterList', - function ( $scope, $controller, $location, Poll, SessionStorage, PollVoterList) { +.controller('PollCreateCtrl', ['$scope', '$rootScope', '$controller', '$location', 'Poll', 'SessionStorage', 'PollVoterList', + function ( $scope, $rootScope, $controller, $location, Poll, SessionStorage, PollVoterList) { $controller('PollAdminCtrl', {$scope:$scope}); $scope.globalVariables.create = true; @@ -356,7 +349,7 @@ angular.module('pollControllers', []) } Poll.add(poll, function (data) { - SessionStorage.save({saved: true}); + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); if ($scope.data.poll.pollType != 'FREE') { SessionStorage.save({'voterList':$scope.data.voterList}) $location.url('/poll/edit/'+data.id+'?token='+data.permission); @@ -371,7 +364,11 @@ angular.module('pollControllers', []) if (angular.isDefined(error.data['choice['+index+'].name'])) { choice.restError = {name:error.data['choice['+index+'].name']}; } - }) + }); + + if (angular.isDefined(error.data.choice)) { + $rootScope.$broadcast('newError', error.data.choice[0]); + } }); } @@ -381,8 +378,8 @@ angular.module('pollControllers', []) }]) -.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', '$location', '$timeout', '$translate', 'Poll', 'PollChoice', 'PollVote', 'PollVoterList', 'PollVoterListMember', 'FavoriteList', 'SessionStorage', - function ( $scope, $controller, $routeParams, $location, $timeout, $translate, Poll, PollChoice, PollVote, PollVoterList, PollVoterListMember, FavoriteList, SessionStorage) { +.controller('PollEditCtrl', ['$scope', '$rootScope', '$controller', '$routeParams', '$location', '$timeout', '$translate', 'Poll', 'PollChoice', 'PollVote', 'PollVoterList', 'PollVoterListMember', 'FavoriteList', 'SessionStorage', + function ( $scope, $rootScope, $controller, $routeParams, $location, $timeout, $translate, Poll, PollChoice, PollVote, PollVoterList, PollVoterListMember, FavoriteList, SessionStorage) { $controller('PollAdminCtrl', {$scope:$scope}); $scope.globalVariables.edit = true; @@ -395,7 +392,7 @@ angular.module('pollControllers', []) PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, choice, function (data) { delete choice.restError; choice.id = data.id; - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); }, function (error) { choice.restError = error.data; }); @@ -404,7 +401,7 @@ angular.module('pollControllers', []) $scope.callBackEditChoice = function (choice) { PollChoice.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, choice, function() { delete choice.restError; - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); }, function (error) { choice.restError = error.data; }); @@ -412,13 +409,16 @@ angular.module('pollControllers', []) $scope.deleteChoice = function (choice) { PollChoice.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission, choiceId: choice.id}, function () { - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); var index = $scope.data.choices.indexOf(choice); if (index > -1) { $scope.data.choices.splice(index,1); } }, function (error) { angular.extend($scope.restError, error.data); + if (angular.isDefined(error.data.choice)) { + $rootScope.$broadcast('newError', error.data.choice[0]); + } }); }; @@ -500,7 +500,7 @@ angular.module('pollControllers', []) $scope.saveVoterList = function (voterList) { if (angular.isDefined(voterList.group.id)) { PollVoterList.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission, voterListId:voterList.group.id}, voterList.group, function (data) { - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); delete voterList.group.restError; }, function (error) { voterList.group.restError = error.data; @@ -519,7 +519,7 @@ angular.module('pollControllers', []) }); if (vl.members.length > 0) { PollVoterList.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, vl, function (data) { - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); voterList.group.id = data.id; delete voterList.group.restError; @@ -577,7 +577,7 @@ angular.module('pollControllers', []) } vlMemberPromise.then(function (data) { - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); member.id = data.id; delete member.restError; }, function (error) { @@ -694,7 +694,7 @@ angular.module('pollControllers', []) } $scope.data.poll.$update({permission:$scope.globalVariables.permission}, function (data) { - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'poll.saved', conf.defaultTimeSuccessSave); }, function (error) { angular.extend($scope.restError, error.data); }); @@ -715,8 +715,8 @@ angular.module('pollControllers', []) }; }]) -.controller('PollVoteCtrl', ['$scope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', '$translate', - function ($scope, $q, $controller, $routeParams, Poll, PollChoice, PollVote, $translate) { +.controller('PollVoteCtrl', ['$scope', '$rootScope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', '$translate', + function ($scope, $rootScope, $q, $controller, $routeParams, Poll, PollChoice, PollVote, $translate) { $controller('PollCtrl', {$scope:$scope}); $scope.tab = $scope.setTab('vote'); @@ -778,7 +778,7 @@ angular.module('pollControllers', []) if (angular.isDefined($scope.data.vote.id)) { // edit vote PollVote.update({pollId:$routeParams.pollId}, sendVote, function (data) { - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'vote.added', conf.defaultTimeSuccessSave); }, function (error) { $scope.data.vote.restError = { voterName : error.data["voter.name"]}; }) @@ -790,7 +790,7 @@ angular.module('pollControllers', []) $scope.data.vote.permission = returnRequest.permission; $scope.data.votants.push(angular.copy($scope.data.vote)); - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'vote.added', conf.defaultTimeSuccessSave); initVote(); }, function (error) { $scope.data.vote.restError = { voterName : error.data["voter.name"]}; @@ -826,8 +826,8 @@ angular.module('pollControllers', []) }]) .controller('PollCommentCtrl', - ['$scope', '$controller', '$routeParams', 'Poll', 'PollComment', '$translate', - function ( $scope, $controller, $routeParams, Poll, PollComment, $translate) { + ['$scope', '$rootScope', '$controller', '$routeParams', 'Poll', 'PollComment', '$translate', + function ( $scope, $rootScope, $controller, $routeParams, Poll, PollComment, $translate) { $controller('PollCtrl', {$scope:$scope}); $scope.tab = $scope.setTab('comment'); @@ -912,7 +912,7 @@ angular.module('pollControllers', []) } commentPromise.then(function () { - $scope.globalVariables.saved = true; + $rootScope.$broadcast('newSuccess', 'comment.added', conf.defaultTimeSuccessSave); //clean form $scope.comment.text = ''; delete $scope.comment.postDate; diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js index 8a3c40d..cb4104e 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js @@ -19,7 +19,13 @@ * #L% */ angular.module('userControllers', []) - .controller('UserRegisterCtrl', ['$scope', 'User', function ($scope, User) { + .controller('UserRegisterCtrl', ['$scope', '$rootScope', '$location', 'User', 'SessionStorage', + function ($scope, $rootScope, $location, User, SessionStorage) { + + if (angular.isDefined(SessionStorage.get().user)) { + $rootScope.$broadcast('newError', 'user.error.logout.mandatory'); + $location.url('/'); + } if (!angular.isDefined($scope.data)) { $scope.data = {}; @@ -29,7 +35,7 @@ $scope.submit = function () { if ($scope.data.user.password == $scope.data.user.password2) { User.add({}, $scope.data.user, function (data) { - $scope.saved = true; + $rootScope.$broadcast('newSuccess', 'user.register.success', conf.defaultTimeSuccessSave); $scope.data.user = {email:'', password:'', password2:''}; }, function (error) { $scope.restError = error.data; @@ -38,12 +44,18 @@ } }]) -.controller('UserLostPasswordCtrl', ['$scope', '$translate', 'UserLostPassword', function ($scope, $translate, UserLostPassword) { +.controller('UserLostPasswordCtrl', ['$scope', '$rootScope', '$translate', '$location', 'SessionStorage', 'UserLostPassword', + function ($scope, $rootScope, $translate, $location, SessionStorage, UserLostPassword) { + if (angular.isDefined(SessionStorage.get().user)) { + $rootScope.$broadcast('newError', 'user.error.logout.mandatory'); + $location.url('/'); + } + $scope.email = ''; $scope.submit = function () { if ($scope.email != '') { UserLostPassword.send({login:$scope.email}, function (data) { - $scope.saved = true; + $rootScope.$broadcast('newSuccess', 'user.forgotPassword.success', conf.defaultTimeSuccessSave); $scope.email = ''; }, function (error) { $translate('user.error.mail.notFound').then(function (error) { @@ -61,14 +73,20 @@ -.controller('UserEditCtrl', ['$scope', 'User', 'SessionStorage', function ($scope, User, SessionStorage) { +.controller('UserEditCtrl', ['$scope', '$rootScope', '$location', 'User', 'SessionStorage', function ($scope, $rootScope, $location, User, SessionStorage) { $scope.currentUser = SessionStorage.get().user; + + if (angular.isUndefined($scope.currentUser)) { + $rootScope.$broadcast('newError', 'user.error.login.mandatory' ); + $location.url('/'); + } + $scope.currentUser.password = ''; $scope.editUser = function () { User.update($scope.currentUser, function (data) { SessionStorage.save({user:data}); - $scope.saved = true; + $rootScope.$broadcast('newSuccess', 'user.edit.success', conf.defaultTimeSuccessSave); }, function (error) { $scope.restError = error.data; }); @@ -78,7 +96,7 @@ if ($scope.currentUser.newPassword == $scope.currentUser.newPassword2) { User.editPassword($scope.currentUser, function (data) { SessionStorage.save({user:data}); - $scope.saved = true; + $rootScope.$broadcast('newSuccess', 'user.edit.success', conf.defaultTimeSuccessSave); }, function (error) { $scope.restError = error.data; }); diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index 74b248b..e819aa8 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -317,6 +317,24 @@ angular.module('pollenServices', ['ngResource']) }) localStorage.setItem(storageId, JSON.stringify(session)); }, + append: function (data) { + angular.forEach(data, function (value, key) { + var field = session[key]; + if (angular.isDefined(field)) { + if (angular.isArray(field)) { + field.push(value); + } + else { + field = [field, value]; + } + } + else { + field = value; + } + session[key] = field; + }); + localStorage.setItem(storageId, JSON.stringify(session)); + }, remove: function (key) { if (angular.isString(key)) { delete session[key]; diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html index 87315b2..58bc694 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll.html @@ -19,10 +19,6 @@ #L% --> <div> - <alert type="danger" class="alert-float" ng-if="restError.choice" close="restError.choice = false"> {{restError.choice[0]}} </alert> - <alert type="success" class="alert-float" ng-if="globalVariables.editMode && globalVariables.saved" close="globalVariables.saved = false">{{ 'poll.saved' | translate }}</alert> - <alert type="success" class="alert-float" ng-if="globalVariables.voteMode && globalVariables.saved" close="globalVariables.saved = false">{{ 'vote.added' | translate }}</alert> - <alert type="success" class="alert-float" ng-if="globalVariables.commentMode && globalVariables.saved" close="globalVariables.saved = false">{{ 'comment.added' | translate }}</alert> <ul class="nav nav-tabs"> <li ng-class="{active: tab == 'home'}"><a href="{{urlTab}}tab=home" ng-click="tab = 'home'"> <span class="glyphicon glyphicon-home"></span> </a></li> diff --git a/pollen-ui-angular/src/main/webapp/partials/user-edit.html b/pollen-ui-angular/src/main/webapp/partials/user-edit.html index ccb0ae2..c995f7d 100644 --- a/pollen-ui-angular/src/main/webapp/partials/user-edit.html +++ b/pollen-ui-angular/src/main/webapp/partials/user-edit.html @@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #L% --> -<alert type="success" class="alert-float" ng-show="saved" close="saved = false"> {{ 'user.edit.success' | translate }} </alert> - <h2> {{ 'title.editUser' | translate }} </h2> <form class="horizontal-form" ng-submit="editUser()"> diff --git a/pollen-ui-angular/src/main/webapp/partials/user-lostPassword.html b/pollen-ui-angular/src/main/webapp/partials/user-lostPassword.html index fbf6890..dd28daa 100644 --- a/pollen-ui-angular/src/main/webapp/partials/user-lostPassword.html +++ b/pollen-ui-angular/src/main/webapp/partials/user-lostPassword.html @@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #L% --> -<alert type="success" class="alert-float" ng-show="saved" close="saved = false"> {{ 'user.forgotPassword.success' | translate }} </alert> - <h2>{{ 'title.forgotPassword' | translate }}</h2> <form ng-submit="submit()" class="form-horizontal"> diff --git a/pollen-ui-angular/src/main/webapp/partials/user-register.html b/pollen-ui-angular/src/main/webapp/partials/user-register.html index a604231..ea75471 100644 --- a/pollen-ui-angular/src/main/webapp/partials/user-register.html +++ b/pollen-ui-angular/src/main/webapp/partials/user-register.html @@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #L% --> -<alert type="success" class="alert-float" ng-show="saved" close="saved = false"> {{ 'user.register.success' | translate }}</alert> - <h2>{{ 'title.register' | translate }}</h2> <form ng-submit="submit()" class="form-horizontal"> @@ -42,7 +40,7 @@ {{ 'user.name' | translate }} </label> <div class="col-sm-6"> - <input type="text" id="formName" name="login" class="form-control" ng-model="data.user.name"/> + <input type="text" id="formName" name="email" class="form-control" ng-model="data.user.name"/> </div> <div class="col-sm-1"> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm