03/13: List favoriteList and create/edit favoriteListMember
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 bbc9778b5cf58d1053336f1384f0809bee2097fa Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue Jun 17 17:54:36 2014 +0200 List favoriteList and create/edit favoriteListMember --- pollen-ui-angular/src/main/webapp/index.html | 7 + pollen-ui-angular/src/main/webapp/js/app.js | 5 +- .../src/main/webapp/js/conf.js.exemple | 3 + .../main/webapp/js/controllers/favoriteListCtrl.js | 184 +++++++++++++++++++++ pollen-ui-angular/src/main/webapp/js/services.js | 14 +- .../main/webapp/partials/favoriteList-edit.html | 46 ++++++ .../main/webapp/partials/favoriteList-list.html | 12 ++ 7 files changed, 269 insertions(+), 2 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/index.html b/pollen-ui-angular/src/main/webapp/index.html index f53360b..a40155a 100644 --- a/pollen-ui-angular/src/main/webapp/index.html +++ b/pollen-ui-angular/src/main/webapp/index.html @@ -48,6 +48,7 @@ <script src="js/services.js"></script> <script src="js/controllers/pollCtrl.js"></script> <script src="js/controllers/userCtrl.js"></script> + <script src="js/controllers/favoriteListCtrl.js"></script> <script src="js/controllers/localeCtrl.js"></script> <script src="i18n/fr.js"></script> @@ -116,6 +117,12 @@ <li class="divider"></li> <li> + <a href="#/favoriteList">{{ 'user.favoriteList' | translate }}</a> + </li> + + <li class="divider"></li> + + <li> <a href="#/poll/list/created"> {{ 'user.listPollCreated' | translate }} </a> </li> diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index 726c14a..c367a04 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', 'localeControllers', 'ui.bootstrap', 'pascalprecht.translate']) +angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'ui.bootstrap', 'pascalprecht.translate']) .config(['$httpProvider', function($httpProvider) { // edit header for locale and sessionToken $httpProvider.interceptors.push('httpInterceptor'); @@ -67,6 +67,9 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC .when('/user/register', {templateUrl: './partials/user-register.html', controller:"UserRegisterCtrl"}) .when('/user/edit', {templateUrl: './partials/user-edit.html', controller:"UserEditCtrl"}) .when('/user/lostpassword', {templateUrl: './partials/user-lostPassword.html', controller:"UserLostPasswordCtrl"}) + .when('/favoriteList', {templateUrl: './partials/favoriteList-list.html', controller:"FavoriteListCtrl"}) + .when('/favoriteList/new', {templateUrl: './partials/favoriteList-edit.html', controller:"FavoriteListEditCtrl"}) + .when('/favoriteList/:favoriteListId', {templateUrl: './partials/favoriteList-edit.html', controller:"FavoriteListEditCtrl"}) .otherwise({redirectTo: '/'}); }]) diff --git a/pollen-ui-angular/src/main/webapp/js/conf.js.exemple b/pollen-ui-angular/src/main/webapp/js/conf.js.exemple index 06021c7..4602e9a 100644 --- a/pollen-ui-angular/src/main/webapp/js/conf.js.exemple +++ b/pollen-ui-angular/src/main/webapp/js/conf.js.exemple @@ -11,6 +11,9 @@ var conf = { // Favorite list number per page favoriteListDefaultPageSize : 15, + // Member in Favorite list number per page + favoriteListMemberDefaultPageSize : 30, + // Default Language for i18n : 'en' or 'fr' defaultLanguage: 'en', } \ No newline at end of file diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/favoriteListCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/favoriteListCtrl.js new file mode 100644 index 0000000..246d29a --- /dev/null +++ b/pollen-ui-angular/src/main/webapp/js/controllers/favoriteListCtrl.js @@ -0,0 +1,184 @@ +/* + * #%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('favoriteListControllers', []) +.controller('FavoriteListCtrl', ['$scope', 'FavoriteList', 'FavoriteListMember', '$translate', '$routeParams', + function ($scope, FavoriteList, FavoriteListMember, $translate, $routeParams) { + $scope.data = {}; + + var paginationParameter = {pageSize: conf.favoriteListDefaultPageSize}; + if (angular.isDefined($routeParams.page)) { + if (angular.isDefined($routeParams.pageSize)) { + paginationParameter = {pageSize:$routeParams.pageSize}; + $scope.pageSize = $routeParams.pageSize; + } + paginationParameter.pageNumber = $routeParams.page; + } + + $scope.$watch('data.favoriteListPagination.currentPage', function (newVal, oldVal) { + // check if the current page has changed + if (angular.isDefined(oldVal) && newVal != oldVal) { + paginationParameter.pageNumber = $scope.data.favoriteListPagination.currentPage; + initFavoriteList(); + } + }); + + var initFavoriteList = function () { + FavoriteList.get({paginationParameter:paginationParameter}, function (data) { + $scope.data.favoriteList = data.elements; + $scope.data.favoriteListPagination = data.pagination; + }); + }; initFavoriteList(); + +}]) + +.controller('FavoriteListEditCtrl', ['$scope', 'FavoriteList', 'FavoriteListMember', '$translate', '$routeParams', '$timeout', '$q', + function ($scope, FavoriteList, FavoriteListMember, $translate, $routeParams, $timeout, $q) { + $scope.data = {}; + + var paginationParameter = {pageSize: conf.favoriteListDefaultPageSize}; + if (angular.isDefined($routeParams.page)) { + if (angular.isDefined($routeParams.pageSize)) { + paginationParameter = {pageSize:$routeParams.pageSize}; + $scope.pageSize = $routeParams.pageSize; + } + paginationParameter.pageNumber = $routeParams.page; + } + + $scope.$watch('data.favoriteListMemberPagination.currentPage', function (newVal, oldVal) { + // check if the current page has changed + if (angular.isDefined(oldVal) && newVal != paginationParameter.pageNumber) { + paginationParameter.pageNumber = newVal; + initFavoriteListMember(); + } + }); + + if ($routeParams.favoriteListId) { + FavoriteList.get({favoriteListId:$routeParams.favoriteListId}, function (favList) { + $scope.data.favoriteList = favList; + initFavoriteListMember(); + }); + } + else { + $scope.data.favoriteList = {name:'', members: []}; + } + + var initFavoriteListMember = function () { + var deferred = $q.defer(); + FavoriteListMember.get({favoriteListId:$routeParams.favoriteListId, paginationParameter:paginationParameter}, function (members) { + $timeout(function () { + $scope.data.favoriteList.members = members.elements; + $scope.data.favoriteListMemberPagination = members.pagination; + deferred.resolve(); + }, 100); + }); + + return deferred.promise; + } + + $scope.addMember = function () { + if (angular.isDefined($scope.data.favoriteListMemberPagination) && $scope.data.favoriteListMemberPagination.currentPage < $scope.data.favoriteListMemberPagination.lastPage) { + paginationParameter.pageNumber = $scope.data.favoriteListMemberPagination.lastPage; + initFavoriteListMember().then($scope.addMember); + } else { + $scope.data.favoriteList.members.push({name:'', email:''}); + } + }; + + $scope.saveFavoriteList = function () { + var FavoriteListPromise; + if (angular.isDefined($scope.data.favoriteList.id)) { // edit + FavoriteListPromise = FavoriteList.update({id:$scope.data.favoriteList.id, name:$scope.data.favoriteList.name}, function (data) { + delete $scope.data.favoriteList.restError; + }, function (error) { + $scope.data.favoriteList.restError = error.data; + }).$promise; + } else { // Create + FavoriteListPromise = FavoriteList.add({name:$scope.data.favoriteList.name}, function (data) { + $scope.data.favoriteList.id = data.id; + delete $scope.data.favoriteList.restError; + }, function (error) { + $scope.data.favoriteList.restError = error.data; + }).$promise; + } + + return FavoriteListPromise; + }; + + $scope.saveMember = function (member) { + if (member.name != '' && member.email != '') { + if (angular.isDefined($scope.data.favoriteList.id)) { + var memberPromise; + if (angular.isDefined(member.id)) { + memberPromise = FavoriteListMember.update({favoriteListId:$scope.data.favoriteList.id}, member).$promise; + } else { + memberPromise = FavoriteListMember.add({favoriteListId:$scope.data.favoriteList.id}, member).$promise; + } + + memberPromise.then(function (data) { + member.id = data.id; + delete member.restError; + }, function (error) { + member.restError = error.data; + }) + } + else { + // create favoriteList + $scope.saveFavoriteList().then(function () { + $scope.saveMember(member); + }); + } + } + } + + $scope.deleteVoterList = function (voterList) { + if (angular.isDefined(voterList) && angular.isDefined(voterList.group.id)) { + var confirmMessage; + $translate('action.message.confirmDelete').then(function (msg) { + confirmMessage = msg; + }).then( function () { + var confirmDelete = confirm(confirmMessage); + if (confirmDelete == true) { + PollVoterList.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission, voterListId:voterList.group.id}, function (data) { + var index = $scope.data.voterList.indexOf(voterList); + $scope.data.voterList.splice(index, 1); + }); + } + }); + } + }; + + $scope.deleteMember = function (member) { + if (angular.isDefined($scope.data.favoriteList.id)) { + var confirmMessage; + $translate('action.message.confirmDelete').then(function (msg) { + confirmMessage = msg; + }).then( function () { + var confirmDelete = confirm(confirmMessage); + if (confirmDelete == true) { + FavoriteListMember.remove({favoriteListId:$scope.data.favoriteList.id, memberId:member.id}, function (data) { + var index = $scope.data.favoriteList.members.indexOf(member); + $scope.data.favoriteList.members.splice(index, 1); + }); + } + }); + } + }; +}]) diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index 332f70e..03579b8 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -259,6 +259,12 @@ angular.module('pollenServices', ['ngResource']) transformRequest: function (data, headersGetter) { return transformParam(data); } + }, + 'update' : { + method:'POST', + transformRequest: function (data, headersGetter) { + return transformParam(data); + } } }) }]) @@ -268,13 +274,19 @@ angular.module('pollenServices', ['ngResource']) return 'member='+encodeURIComponent(JSON.stringify(data)); } - return $resource(conf.restURL+'/favoriteLists/:favoriteListId/members/:memberId', {favoriteListId:'@id'}, + return $resource(conf.restURL+'/favoriteLists/:favoriteListId/members/:memberId', {memberId:'@id'}, { 'add' : { method:'POST', transformRequest: function (data, headersGetter) { return transformParam(data); } + }, + 'update' : { + method:'POST', + transformRequest: function (data, headersGetter) { + return transformParam(data); + } } }) }]) diff --git a/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html b/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html new file mode 100644 index 0000000..257b333 --- /dev/null +++ b/pollen-ui-angular/src/main/webapp/partials/favoriteList-edit.html @@ -0,0 +1,46 @@ +<h1> {{ 'user.favoriteList' | translate }} </h1> + +<div> + <table class="voterList"> + <tr> + <th colspan="2" ng-class="{'has-success':data.favoriteList.id && !data.favoriteList.restError}"> + <input type="text" + name="group" + ng-model="data.favoriteList.name" + placeholder="name group" + class="form-control" + ng-class="{'has-error':data.favoriteList.restError.name}" + auto-save="saveFavoriteList()" /> + </th> + <th class="action"> </th> + </tr> + + <tr> + <th> {{ 'poll.restricted.name' | translate }} </th> + <th> {{ 'poll.restricted.mail' | translate }} </th> + <th class="action"> </th> + </tr> + + <tr ng-repeat="member in data.favoriteList.members" ng-class="{'has-success':member.id && !member.restError}"> + <td> <div ng-class="{'has-error':member.restError.name}"><input type="text" ng-model="member.name" class="form-control" auto-save="saveMember(member)"/></div></td> + <td> <div ng-class="{'has-error':member.restError.email}"><input type="text" ng-model="member.email" class="form-control" auto-save="saveMember(member)" /></div></td> + <td class="action"> <div ng-show="member.id"><button class="btn btn-danger" ng-click="deleteMember(member);"><i class="glyphicon glyphicon-remove"></i></button></div></td> + </tr> + + <tr> + <th colspan="3" ng-show="data.favoriteListMemberPagination.lastPage > 0"> + <make-pagination current-page="data.favoriteListMemberPagination.currentPage" + last-page="data.favoriteListMemberPagination.lastPage" + page-size="data.favoriteListMemberPagination.pageSize"></make-pagination> + </th> + </tr> + + <tr> + <th colspan="3"> + <button class="btn btn-info" ng-click="addMember();"> {{ 'action.favoriteList.addMember' | translate }} </button> + <button class="btn btn-danger" ng-click="deleteFavoriteList();" ng-show="favoriteList.id"> {{ 'action.favoriteList.delete' | translate }} </button> + </th> + </tr> + </table> + +</div> \ No newline at end of file diff --git a/pollen-ui-angular/src/main/webapp/partials/favoriteList-list.html b/pollen-ui-angular/src/main/webapp/partials/favoriteList-list.html new file mode 100644 index 0000000..840685a --- /dev/null +++ b/pollen-ui-angular/src/main/webapp/partials/favoriteList-list.html @@ -0,0 +1,12 @@ +<h1> {{ 'user.favoriteList' | translate }} </h1> + +<div> + <div ng-repeat="favList in data.favoriteList"> + <h2> <a href="#/favoriteList/{{favList.id}}">{{ favList.name }}</a></h2> + <hr/> + </div> + + <make-pagination current-page="data.favoriteListPagination.currentPage" + last-page="data.favoriteListPagination.lastPage" + page-size="data.favoriteListPagination.pageSize"></make-pagination> +</div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm