02/03: UI get voteCountingType from server
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 a02e287b235048245fd512b5006b7b18a0284644 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Thu Jul 3 16:45:23 2014 +0200 UI get voteCountingType from server --- .../pollen/services/bean/VoteCountingTypeBean.java | 23 ++-- .../src/main/webapp/js/controllers/localeCtrl.js | 3 +- .../src/main/webapp/js/controllers/pollCtrl.js | 126 +++++++++++++-------- pollen-ui-angular/src/main/webapp/js/services.js | 9 ++ .../src/main/webapp/partials/inline-poll.html | 4 +- .../src/main/webapp/partials/poll-settings.html | 12 +- 6 files changed, 110 insertions(+), 67 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java index 8e86c07..4ccb153 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java @@ -1,12 +1,7 @@ package org.chorem.pollen.services.bean; -import org.chorem.pollen.services.service.VoteCountingService; -import org.chorem.pollen.votecounting.VoteCounting; -import org.chorem.pollen.votecounting.VoteCountingFactory; import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType; -import java.util.Locale; - /** * Created on 03/07/14. * @@ -23,7 +18,7 @@ public class VoteCountingTypeBean { protected String shortHelper; - protected ChoiceToVoteRenderType renderType; + protected String renderType; public int getId() { @@ -58,11 +53,23 @@ public class VoteCountingTypeBean { this.shortHelper = shortHelper; } - public ChoiceToVoteRenderType getRenderType() { + public String getRenderType() { return renderType; } - public void setRenderType(ChoiceToVoteRenderType renderType) { + public void setRenderType(String renderType) { this.renderType = renderType; } + + public void setRenderType(ChoiceToVoteRenderType renderType) { + switch (renderType) { + case CHECKBOX: + this.renderType = "checkbox"; + break; + + case TEXTFIELD: + this.renderType = "text"; + break; + } + } } diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js index d370ab8..9805d8b 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js @@ -19,7 +19,7 @@ * #L% */ angular.module('localeControllers', []) -.controller('LocaleCtrl', ['$scope', '$translate', 'SessionStorage',function ($scope, $translate, SessionStorage) { +.controller('LocaleCtrl', ['$scope', '$rootScope', '$translate', 'SessionStorage',function ($scope, $rootScope, $translate, SessionStorage) { $scope.debug = conf.debug; $scope.locale = SessionStorage.get().locale; if (angular.isUndefined($scope.locale)) { @@ -42,6 +42,7 @@ angular.module('localeControllers', []) SessionStorage.save({locale:locale}); $scope.locale = locale; $translate.use(locale); + $rootScope.$broadcast('switchLocale'); } } }]) 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 68baa88..dd4bbef 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -67,16 +67,32 @@ angular.module('pollControllers', []) SessionStorage.save({'menuMinify': $scope.globalVariables.minify}); } - $translate('dateFormat').then(function (dateFormat) { - $scope.globalVariables.dateFormat = dateFormat; - }); + var setDateFormat = function () { + $translate('dateFormat').then(function (dateFormat) { + $scope.globalVariables.dateFormat = dateFormat; + }); + }; setDateFormat(); + + $scope.$on('switchLocale', function() { + setDateFormat(); + }) $scope.data = {}; $scope.data.poll = {}; + $scope.pollDeferred = $q.defer(); + + var setVoteCountingType = function () { + $scope.pollDeferred.promise.then(function () { + Poll.voteCountingType({id:$scope.data.poll.voteCountingType}, function (data) { + $scope.data.voteCountingType = data; + $scope.pollDeferred.resolve(); + }) + }); + } + if (angular.isDefined($routeParams.pollId)) { - var pollDeferred = $q.defer(); - $scope.pollDeferred = pollDeferred; + var pollDeferred = $scope.pollDeferred; Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, function (poll) { $scope.data.poll = poll; $scope.globalVariables.pollToken = poll.permission; @@ -95,6 +111,10 @@ angular.module('pollControllers', []) }); pollDeferred.promise.then(function () { + setVoteCountingType(); + }) + + pollDeferred.promise.then(function () { var baseUrl = window.location.protocol+'//'+window.location.hostname+window.location.pathname; $scope.globalVariables.baseUrl = baseUrl; $scope.globalVariables.linkHome = baseUrl; @@ -156,13 +176,6 @@ angular.module('pollControllers', []) } }); - $scope.getInputType = function () { - if ($scope.voteCountingIsBoolean()) { - return 'checkbox'; - } else { - return 'text'; - } - } $scope.getChoiceValue = function (choiceValue) { if ($scope.voteCountingIsBoolean()) { @@ -176,27 +189,32 @@ angular.module('pollControllers', []) return 0.0; } else { - choiceValue; + return choiceValue; } } } $timeout(function () { - $scope.$watch('data.poll.voteCountingType', function (newVal, oldVal) { - if (angular.isDefined(oldVal) && (newVal == 1 || oldVal == 1) && newVal != oldVal) { - angular.forEach($scope.data.votants, function(votant, key) { - angular.forEach(votant.choice, function (choice) { - choice.inputType = $scope.getInputType(); - choice.voteValue = $scope.getChoiceValue(choice.voteValue); - }) - }); - } - }) + $scope.$watch('data.poll.voteCountingType', function (newVal, oldVal) { + if (newVal != oldVal && oldVal !== undefined) { + setVoteCountingType(); + } + }); + + $scope.$watch('data.voteCountingType.renderType', function (newVal, oldVal) { + if (newVal !== undefined) { + angular.forEach($scope.data.votants, function(votant, key) { + angular.forEach(votant.choice, function (choice) { + choice.voteValue = $scope.getChoiceValue(choice.voteValue); + }); + }); + } + }) }); $scope.voteCountingIsBoolean = function () { - if (angular.isDefined($scope.data.poll) && angular.isDefined($scope.data.poll.voteCountingType)) { - return $scope.data.poll.voteCountingType == 1; + if (angular.isDefined($scope.data.voteCountingType)) { + return $scope.data.voteCountingType.renderType == 'checkbox'; } return false; } @@ -247,7 +265,7 @@ angular.module('pollControllers', []) }]) -.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$timeout', '$routeParams', function ($scope, $controller, $modal, $timeout, $routeParams) { +.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$timeout', '$routeParams', 'Poll', function ($scope, $controller, $modal, $timeout, $routeParams, Poll) { $controller('PollCtrl', {$scope:$scope}); $scope.tab = $scope.setTab('edit'); @@ -315,8 +333,7 @@ angular.module('pollControllers', []) return { name: '', date: $scope.globalVariables.lastDate, - choiceType: $scope.globalVariables.lastType, - inputType: $scope.getInputType() + choiceType: $scope.globalVariables.lastType }; } @@ -399,6 +416,35 @@ angular.module('pollControllers', []) return 'Non'; } } + + //////////////////////////////// + //// VOTE COUNTING TYPE ///// + //////////////////////////////// + + var initVoteCountingType = function () { + Poll.allVoteCountingType(function (data) { + $scope.data.allVoteCountingType = data; + setHelper(); + }) + }; initVoteCountingType(); + + var setHelper = function () { + angular.forEach($scope.data.allVoteCountingType, function (value) { + if (value.id == $scope.data.poll.voteCountingType) { + $scope.voteCountingTypeHelper = value.helper; + } + }); + }; + + $scope.$on('switchLocale', function() { + initVoteCountingType(); + }); + + $timeout(function () { + $scope.$watch('data.poll.voteCountingType', function (newVal) { + setHelper(); + }) + }); }]) .controller('PollCreateCtrl', ['$scope', '$rootScope', '$controller', '$location', 'Poll', 'SessionStorage', 'PollVoterList', @@ -770,15 +816,7 @@ angular.module('pollControllers', []) $scope.data.votants = votes; angular.forEach($scope.data.votants, function (vote) { angular.forEach(vote.choice, function (choice) { - if ($scope.voteCountingIsBoolean()) { - if (choice.voteValue != null && choice.voteValue != 0.0) { - choice.voteValue = true; - } - else { - choice.voteValue = false; - } - } - choice.inputType = $scope.getInputType(); + choice.voteValue = $scope.getChoiceValue(choice.voteValue); }) }) }); @@ -843,15 +881,7 @@ angular.module('pollControllers', []) $scope.data.votants = votes; angular.forEach($scope.data.votants, function (vote) { angular.forEach(vote.choice, function (choice) { - if ($scope.voteCountingIsBoolean()) { - if (choice.voteValue != null && choice.voteValue != 0.0) { - choice.voteValue = true; - } - else { - choice.voteValue = false; - } - } - choice.inputType = $scope.getInputType(); + choice.voteValue = $scope.getChoiceValue(choice.voteValue); }) }) }); @@ -891,7 +921,7 @@ angular.module('pollControllers', []) for (var i = 0; i < $scope.data.choices.length; ++i) { - $scope.data.vote.choice.push({'choiceId':$scope.data.choices[i].id, 'voteValue': defaultValue, 'inputType': $scope.getInputType()}); + $scope.data.vote.choice.push({'choiceId':$scope.data.choices[i].id, 'voteValue': defaultValue}); } } @@ -956,7 +986,7 @@ angular.module('pollControllers', []) } $scope.toggleValue = function (choice, event) { - if (choice.inputType == 'checkbox') { + if ($scope.data.voteCountingType.renderType == 'checkbox') { choice.voteValue = !choice.voteValue; event.stopPropagation(); } diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index 1333cae..c9495f8 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -56,6 +56,15 @@ angular.module('pollenServices', ['ngResource']) 'clone' : { method : 'POST', url : conf.restURL+'/polls/:pollId/clone' + }, + 'allVoteCountingType': { + method : 'GET', + isArray: true, + url : conf.restURL+'/voteCountingTypes/:id' + }, + 'voteCountingType': { + method : 'GET', + url : conf.restURL+'/voteCountingTypes/:id' } }); }]) diff --git a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html index d5f4474..6061367 100644 --- a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html @@ -60,7 +60,7 @@ </input-error> </td> <td ng-repeat="choice in data.vote.choice" class="pollChoice" ng-class="{voteTrue:choice.voteValue, voteFalse:!choice.voteValue}" ng-click="toggleValue(choice, $event);"> - <input type="{{choice.inputType}}" name="{{choice.choiceId}}" ng-model="choice.voteValue" ng-click="toggleValue(choice, $event);" /> + <input type="{{data.voteCountingType.renderType}}" name="{{choice.choiceId}}" ng-model="choice.voteValue" ng-click="toggleValue(choice, $event);" /> </td> <td> <input class="btn btn-primary btn-large" type="button" value="{{ 'action.vote' | translate }}" ng-click="voter()" /> @@ -72,7 +72,7 @@ <tr ng-repeat="vote in data.votants track by $index" class="pollAnim"> <td class="pollChoice"> {{vote.voterName}}</td> <td ng-repeat="choice in vote.choice" class="pollChoice" ng-class="{voteTrue:choice.voteValue, voteFalse:!choice.voteValue}"> - <input type="{{choice.inputType}}" ng-model="choice.voteValue" disabled /> + <input type="{{data.voteCountingType.renderType}}" ng-model="choice.voteValue" disabled /> </td> <td> <button class="btn btn-info" ng-if="vote.permission && !globalVariables.editMode" ng-click="editVote(vote)"><span class="glyphicon glyphicon-pencil"></span></button> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-settings.html b/pollen-ui-angular/src/main/webapp/partials/poll-settings.html index 06d4df7..99df8ab 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-settings.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-settings.html @@ -130,15 +130,11 @@ <label class="col-sm-4 control-label">Type : </label> <div class="col-sm-8"> <div class="btn-group"> - <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="1" auto-save="autoSavePoll()">Normal</button> - <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="2" auto-save="autoSavePoll()">Pourcentage</button> - <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="3" auto-save="autoSavePoll()">Condorcet</button> - <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="4" auto-save="autoSavePoll()">Nombre</button> - <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="5" auto-save="autoSavePoll()">Borda</button> - <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="6" auto-save="autoSavePoll()">Vote alternatif</button> - <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="7" auto-save="autoSavePoll()">Coombs</button> + + <button ng-repeat="voteCountingType in data.allVoteCountingType" type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="{{voteCountingType.id}}" auto-save="autoSavePoll()">{{voteCountingType.name}}</button> + </div> - <p>Description du types de vote</p> + <p ng-bind-html="toHTML(voteCountingTypeHelper)"></p> </div> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm