01/01: pagination is now fluid
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 b7df3cee3096ca13da7cbf596e008aa5d29702d1 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jun 4 14:30:19 2014 +0200 pagination is now fluid --- pollen-ui-angular/src/main/webapp/i18n/en.js | 5 ++ pollen-ui-angular/src/main/webapp/i18n/fr.js | 5 ++ pollen-ui-angular/src/main/webapp/index.html | 1 + pollen-ui-angular/src/main/webapp/js/app.js | 21 ++++++++ .../src/main/webapp/js/controllers/pollCtrl.js | 56 +++++++++++++++------- .../src/main/webapp/partials/pagination.html | 16 ++++--- .../src/main/webapp/partials/poll-comment.html | 2 +- .../src/main/webapp/partials/poll-link.html | 10 +++- 8 files changed, 90 insertions(+), 26 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/i18n/en.js b/pollen-ui-angular/src/main/webapp/i18n/en.js index b44924c..af7e51c 100644 --- a/pollen-ui-angular/src/main/webapp/i18n/en.js +++ b/pollen-ui-angular/src/main/webapp/i18n/en.js @@ -3,6 +3,7 @@ var translateEN = { 'title.forgotPassword' : 'Forget Password', 'title.register' : 'Register', 'title.editUser' : 'Edit Profile', +'title.comment' : 'Comment', 'newPoll' : 'New Poll', @@ -37,6 +38,9 @@ var translateEN = { 'poll.tab.edit' : 'Edit', 'poll.tab.conf' : 'Configuration', +'poll.link.edit' : 'Edit Url:', +'poll.link.vote' : 'Vote Url:', + 'poll.edit' : 'Click to edit', 'poll.desc' : 'Description is optional. This message will not visible in vote page.', 'poll.saved' : 'Poll saved.', @@ -56,6 +60,7 @@ var translateEN = { 'action.save' : 'Save', 'action.delete' : 'Delete', 'action.vote' : 'Vote', +'action.comment' : 'Comment', 'dateFormat' : 'MM-dd-yy', diff --git a/pollen-ui-angular/src/main/webapp/i18n/fr.js b/pollen-ui-angular/src/main/webapp/i18n/fr.js index c7a2022..481260d 100644 --- a/pollen-ui-angular/src/main/webapp/i18n/fr.js +++ b/pollen-ui-angular/src/main/webapp/i18n/fr.js @@ -3,6 +3,7 @@ var translateFR = { 'title.forgotPassword' : 'Récupération du Mot de Passe', 'title.register' : 'Inscription', 'title.editUser' : 'Modification de votre profile', +'title.comment' : 'Laisser un Commentaire', 'newPoll' : 'Nouveau Sondage', @@ -37,6 +38,9 @@ var translateFR = { 'poll.tab.edit' : 'Éditer', 'poll.tab.conf' : 'Configuration', +'poll.link.edit' : 'Lien d\'édition :', +'poll.link.vote' : 'Lien de partage pour le vote :', + 'poll.edit' : 'Clique pour éditer', 'poll.desc' : 'Description (Facultatif). Ce cadre disparait si aucune description n\'est mise', 'poll.saved' : 'Sondage sauvegardé', @@ -55,6 +59,7 @@ var translateFR = { 'action.save' : 'Sauvegarder', 'action.delete' : 'Supprimer', 'action.vote' : 'Voter', +'action.comment' : 'Commenter', 'dateFormat' : 'dd/MM/yyyy', diff --git a/pollen-ui-angular/src/main/webapp/index.html b/pollen-ui-angular/src/main/webapp/index.html index 150738f..0b6eb28 100644 --- a/pollen-ui-angular/src/main/webapp/index.html +++ b/pollen-ui-angular/src/main/webapp/index.html @@ -59,6 +59,7 @@ <ul class="dropdown-menu"> <li><a ng-click="switchLocale('fr')"><img src="img/fr.png" /> Français </a></li> <li><a ng-click="switchLocale('en')"><img src="img/en.png" /> English </a> </li> + <li><a ng-click="switchLocale('no')"> No Translate </a> </li> </ul> </li> </ul> diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index ef8eec1..34a0dbf 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -218,13 +218,34 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }, templateUrl: 'partials/pagination.html', link: function (scope, element, attrs) { + var setNavPage = function (pageNumber) { + if (scope.currentPage > 0) { + scope.previousPage = scope.currentPage - 1; + } else { + scope.previousPage = 0; + } + + if (scope.currentPage < scope.lastPage) { + scope.nextPage = scope.currentPage + 1; + } else { + scope.nextPage = scope.lastPage; + } + } + //set pageList scope.pageList = []; scope.$watch('lastPage', function (newVal) { + scope.pageList = []; for (var i = 0; i <= newVal; i++) { scope.pageList.push(i); } + setNavPage(); }); + + scope.goPage = function (pageNumber) { + scope.currentPage = pageNumber; + setNavPage(); + }; } } }) 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 40bb888..5998a76 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -489,9 +489,21 @@ angular.module('pollControllers', []) paginationParameter.pageNumber = $routeParams.page; } - PollComment.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission, paginationParameter:paginationParameter}, function (data) { - $scope.data.comments = data.elements; - $scope.data.commentsPagination = data.pagination; + var initComments = function () { + if (angular.isUndefined(paginationParameter.pageNumber) || paginationParameter.pageNumber != $scope.data.commentsPagination.pageNumber) { + console.log(paginationParameter); + PollComment.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission, paginationParameter:paginationParameter}, function (data) { + $scope.data.comments = data.elements; + $scope.data.commentsPagination = data.pagination; + }); + } + }; initComments(); + + $scope.$watch('data.commentsPagination.currentPage', function (newVal, oldVal) { + if (angular.isDefined(oldVal) && newVal != oldVal) { + paginationParameter.pageNumber = $scope.data.commentsPagination.currentPage; + initComments(); + } }); $scope.postComment = function () { @@ -502,7 +514,9 @@ angular.module('pollControllers', []) $scope.comment.id = data.id; $scope.comment.permission = data.permission; $scope.comment.postDate = new Date(); - $scope.data.comments.push(angular.copy($scope.comment)); + + // reload comments + initComments(); //clean form $scope.comment.text = ''; @@ -578,19 +592,29 @@ angular.module('pollControllers', []) paginationParameter.pageNumber = $routeParams.page; } - var pollPromise; - if (angular.isDefined($routeParams.cmd)) { - pollPromise = Poll.get({cmd:$routeParams.cmd, paginationParameter:paginationParameter}).$promise; - } - else { - pollPromise = Poll.get({paginationParameter:paginationParameter}).$promise; - } + var initPolls = function () { + var pollPromise; + if (angular.isDefined($routeParams.cmd)) { + pollPromise = Poll.get({cmd:$routeParams.cmd, paginationParameter:paginationParameter}).$promise; + } + else { + pollPromise = Poll.get({paginationParameter:paginationParameter}).$promise; + } - pollPromise.then(function (data) { - $scope.data.polls = data.elements - $scope.data.pollsPagination = data.pagination; - }, function (error) { - $scope.restError = {forbidden:true}; + pollPromise.then(function (data) { + $scope.data.polls = data.elements + $scope.data.pollsPagination = data.pagination; + }, function (error) { + $scope.restError = {forbidden:true}; + }); + }; initPolls(); + + $scope.$watch('data.pollsPagination.currentPage', function (newVal, oldVal) { + // check if the current page has changed + if (angular.isDefined(oldVal) && newVal != oldVal) { + paginationParameter.pageNumber = $scope.data.pollsPagination.currentPage; + initPolls(); + } }); }]) diff --git a/pollen-ui-angular/src/main/webapp/partials/pagination.html b/pollen-ui-angular/src/main/webapp/partials/pagination.html index d82635f..c32bab3 100644 --- a/pollen-ui-angular/src/main/webapp/partials/pagination.html +++ b/pollen-ui-angular/src/main/webapp/partials/pagination.html @@ -1,11 +1,13 @@ <ul class="pagination" ng-show="pageList.length > 1"> - <li ng-class="{disabled:currentPage == 0}"> - <a ng-if="currentPage != 0" href="{{url}}page={{currentPage-1}}&pageSize={{pageSize}}">«</a> - <a ng-if="currentPage == 0">«</a> + <li ng-class="{disabled:currentPage == 0}" ng-click="goPage(previousPage)"> + <a>«</a> </li> - <li ng-repeat="page in pageList" ng-class="{active:currentPage == page}"><a href="{{url}}page={{page}}&pageSize={{pageSize}}">{{page+1}}</a></li> - <li ng-class="{disabled:currentPage == lastPage}"> - <a ng-if="currentPage != lastPage" href="{{url}}page={{currentPage+1}}&pageSize={{pageSize}}">»</a> - <a ng-if="currentPage == lastPage">»</a> + + <li ng-repeat="page in pageList" ng-class="{active:currentPage == page}" ng-click="goPage(page)"> + <a>{{page+1}}</a> + </li> + + <li ng-class="{disabled:currentPage == lastPage}" ng-click="goPage(nextPage)"> + <a>»</a> </li> </ul> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-comment.html b/pollen-ui-angular/src/main/webapp/partials/poll-comment.html index a519b13..d10bf4f 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-comment.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-comment.html @@ -19,7 +19,7 @@ #L% --> <div ng-controller="PollCommentCtrl"> - <h2>Commentaire:</h2> + <h2>{{ 'title.comment' | translate }}</h2> <!-- begin for add comment --> <form ng-submit="postComment()"> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-link.html b/pollen-ui-angular/src/main/webapp/partials/poll-link.html index fefdde1..36e3e4c 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-link.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-link.html @@ -21,6 +21,12 @@ <div> <h2>Sondage:</h2> - <alert type="warning" ng-if="globalVariables.linkEdit && data.poll.permission"> Lien d'édition : <input type="text" select-on-click value="{{globalVariables.linkEdit}}" readonly class="form-control"/> </alert> - <alert type="success" ng-if="globalVariables.linkVote"> Lien de partage pour le vote : <input type="text" select-on-click value="{{globalVariables.linkVote}}" readonly class="form-control"/> </alert> + <alert type="warning" ng-if="globalVariables.linkEdit && data.poll.permission"> + {{ 'poll.link.edit' | translate }} + <input type="text" select-on-click value="{{globalVariables.linkEdit}}" readonly class="form-control"/> + </alert> + <alert type="success" ng-if="globalVariables.linkVote"> + {{ 'poll.link.vote' | translate }} + <input type="text" select-on-click value="{{globalVariables.linkVote}}" readonly class="form-control"/> + </alert> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm