Author: garandel Date: 2014-05-15 12:23:42 +0200 (Thu, 15 May 2014) New Revision: 3943 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3943 Log: add persistance vote Added: trunk/pollen-ui-angular/src/main/webapp/partials/poll-settings.html Removed: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html Modified: trunk/pollen-ui-angular/src/main/webapp/css/style.css trunk/pollen-ui-angular/src/main/webapp/js/app.js trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js trunk/pollen-ui-angular/src/main/webapp/js/services.js trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html trunk/pollen-ui-angular/src/main/webapp/partials/poll.html Modified: trunk/pollen-ui-angular/src/main/webapp/css/style.css =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/css/style.css 2014-05-14 14:09:23 UTC (rev 3942) +++ trunk/pollen-ui-angular/src/main/webapp/css/style.css 2014-05-15 10:23:42 UTC (rev 3943) @@ -195,4 +195,4 @@ .danger { color: #a94442; -} \ No newline at end of file +} Modified: trunk/pollen-ui-angular/src/main/webapp/js/app.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-14 14:09:23 UTC (rev 3942) +++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-15 10:23:42 UTC (rev 3943) @@ -145,3 +145,4 @@ } } }) + Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-14 14:09:23 UTC (rev 3942) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-15 10:23:42 UTC (rev 3943) @@ -129,17 +129,6 @@ }); } - $scope.popupSettings = function () { - var modalInstance = $modal.open({ - templateUrl : 'partials/poll-popupSettings.html', - controller : PollPopupSettingsCtrl, - size : 'lg', - resolve : { poll: function () { - return $scope.data.poll; - } - } - }); - } var PollPopChoiceCtrl = function ($scope, $filter, $modalInstance, title, choice) { $scope.title = title; @@ -164,58 +153,13 @@ } - var PollPopupSettingsCtrl = function ($scope, $filter, $modalInstance, poll) { - $scope.poll = poll; - $scope.toDay = new Date(); - - $scope.$watch('poll.beginDate', function() { - if (poll.beginChoiceDate) { - if (poll.beginChoiceDate < poll.beginDate) { - poll.beginChoiceDate = poll.beginDate; - } - } - else { - poll.beginChoiceDate = poll.beginDate; - } - }); - - $scope.$watch('poll.endDate', function() { - if (poll.endChoiceDate) { - if (poll.endChoiceDate > poll.endDate) { - poll.endChoiceDate = poll.endDate; - } - } - else { - poll.endChoiceDate = poll.endDate; - } - }); - - if (!angular.isDefined($scope.poll.continuousResults)) { - $scope.poll.continuousResults = false; + $scope.printCheckbox= function (value) { + if (value) { + return 'Oui'; + } else { + return 'Non'; } - - if (!angular.isDefined($scope.poll.resultVisibility)) { - $scope.poll.resultVisibility = 'EVERYBODY'; - } - - if (!angular.isDefined($scope.poll.choiceAddAllowed)) { - $scope.poll.choiceAddAllowed = false; - } - - $scope.close = function () { - $modalInstance.dismiss(); - } - - $scope.printCheckbox= function (value) { - if (value) { - return 'Oui'; - } else { - return 'Non'; - } - } } - - }]) .controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', '$cookieStore', function ($scope, $controller, $location, Poll, $cookieStore) { @@ -356,31 +300,21 @@ var initVote = function () { $scope.data.vote = {}; - $scope.data.vote.name = ""; - $scope.data.vote.choices = []; + $scope.data.vote.voter = {name : ""}; + $scope.data.vote.anonymous = false; + $scope.data.vote.voteToChoices = []; for (var i = 0; i < $scope.data.choices.length; ++i) { - if ($scope.data.choices[i].choiceType == 'TEXT') { - $scope.data.vote.choices.push({name:$scope.data.choices[i].name, value:false}); - } - else if ($scope.poll.choices[i].choiceType == 'DATE') { - $scope.data.choices.push({name: $scope.data.choices[i].date , value:false}); - } + $scope.data.vote.voteToChoices.push({choiceId:$scope.data.choices[i].topiaId, voteValue:false}); } } PollVote.query({pollId:$routeParams.pollId}, function (data) { - console.log(data); $scope.data.votants = data; }) $scope.voter = function () { if ($scope.data.vote.name != '') { - var data = {}; - data.name = $scope.data.vote.name; - data.choices = angular.copy($scope.data.vote.choices); - $scope.data.votants.push(data); - - PollVote.add({pollId:$routeParams.pollId, permission:$scope.data.poll.creator.permission.token}, data, function (returnRequest) { + PollVote.add({pollId:$routeParams.pollId}, $scope.data.vote, function (returnRequest) { console.log(returnRequest); }); Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-14 14:09:23 UTC (rev 3942) +++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-15 10:23:42 UTC (rev 3943) @@ -67,11 +67,7 @@ .factory('PollVote', ['$resource', function ($resource) { var transformParam = function (data) { - var obj = {}; - obj.voter = {name : data.name} - obj.voteToChoice = angular.copy(data.choices); - - return 'vote='+encodeURIComponent(JSON.stringify(obj)); + return 'vote='+encodeURIComponent(JSON.stringify(data)); }; return $resource(conf.restURL+'/polls/:pollId/votes/:voteId', {voteId : '@topiaId'}, Modified: trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-14 14:09:23 UTC (rev 3942) +++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-15 10:23:42 UTC (rev 3943) @@ -50,9 +50,9 @@ <!-- begin input vote --> <tr ng-show="!globalVariables.editMode"> - <td class="pollChoice"> <input type="text" class="form-control" placeholder="votre nom" ng-model="data.vote.name" /> </td> - <td ng-repeat="choice in data.vote.choices" class="pollChoice"> - <input type="checkbox" name="$index" ng-model="choice.value"/> + <td class="pollChoice"> <input type="text" class="form-control" placeholder="votre nom" ng-model="data.vote.voter.name" /> </td> + <td ng-repeat="choice in data.vote.voteToChoices" class="pollChoice"> + <input type="checkbox" name="{{choice.choice.topiaId}}" ng-model="choice.voteValue"/> </td> <td> <input class="btn btn-primary btn-large" type="button" value="Vote" ng-click="voter()" /> Deleted: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html 2014-05-14 14:09:23 UTC (rev 3942) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html 2014-05-15 10:23:42 UTC (rev 3943) @@ -1,163 +0,0 @@ -<!-- - #%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% - --> - - - -<form class="form-horizontal"> - <div class="modal-header"> - <h3 class="modal-title">Configuration</h3> - </div> - - <div class="modal-body"> - - <h4>Confiuration global</h4> - - <div class="form-group"> - <label class="col-lg-4 control-label" for="popBeginDate">Date de début : </label> - <div class="col-lg-8"> - <input id="popBeginDate" class="form-control" type="text" - datepicker-popup="dd/MM/yyyy" - min-date="toDay" - max-date="poll.endDate" - ng-model="poll.beginDate" - is-open="beginDateOpened" - ng-click="beginDateOpened = true" /> - </div> - </div> - - <div class="form-group"> - <label class="col-lg-4 control-label" for="popEndDate">Date de fin : </label> - <div class="col-lg-8"> - <input id="popEndDate" class="form-control" type="text" - datepicker-popup="dd/MM/yyyy" - min-date="poll.beginDate" - ng-model="poll.endDate" - is-open="endDateOpened" - ng-click="endDateOpened = true" /> - </div> - </div> - - <div class="form-group"> - <label class="col-lg-4 control-label">Résultat : </label> - <div class="col-lg-8 btn-group"> - <button type="button" class="btn btn-success" ng-model="poll.resultVisibility" btn-radio="'EVERYBODY'">Public</button> - <button type="button" class="btn btn-success" ng-model="poll.resultVisibility" btn-radio="'VOTER'">Participants</button> - <button type="button" class="btn btn-success" ng-model="poll.resultVisibility" btn-radio="'CREATOR'">Créateur</button> - </div> - </div> - - <div class="form-group"> - <label class="col-lg-4 control-label" for="popContinuousResults">Résultat continue : </label> - <div class="col-lg-8"> - <button class="btn btn-default" id="popContinuousResults" ng-model="poll.continuousResults" btn-checkbox>{{printCheckbox(poll.continuousResults)}}</button> - </div> - </div> - - <h4>Configuration des Choix</h4> - - <div class="form-group"> - <label class="col-lg-4 control-label" for="popChoiceAddAllowed">Ajout de choix par les votants :</label> - <div class="col-lg-8"> - <button class="btn btn-default" id="popChoiceAddAllowed" ng-model="poll.choiceAddAllowed" btn-checkbox >{{printCheckbox(poll.choiceAddAllowed)}}</button> - </div> - </div> - <div class="form-group" ng-show="poll.choiceAddAllowed"> - <label class="col-lg-4 control-label" for="popBeginChoiceDate">Date de début : </label> - <div class="col-lg-8"> - <input class="form-control" type="text" id="popBeginChoiceDate" - datepicker-popup="dd/MM/yyyy" - min-date="poll.beginDate" - max-date="poll.endChoiceDate" - ng-model="poll.beginChoiceDate" - is-open="beginChoiceDateOpened" - ng-click="beginChoiceDateOpened = true" /> - </div> - </div> - <div class="form-group" ng-if="poll.choiceAddAllowed" for="popEndChoiceDate"> - <label class="col-lg-4 control-label">Date de fin : </label> - <div class="col-lg-8"> - <input class="form-control" type="text" id="popEndChoiceDate" - datepicker-popup="dd/MM/yyyy" - min-date="poll.beginChoiceDate" - max-date="poll.endDate" - - ng-model="poll.endChoiceDate" - is-open="endChoiceDateOpened" - ng-click="endChoiceDateOpened = true" /> - </div> - </div> - - <div class="form-group"> - <label class="col-lg-4 control-label" for="popLimitedVote">Limiter les votes :</label> - <div class="col-lg-8"> - <button class="btn btn-default" id="popLimitedVote" ng-model="poll.limitedVote" btn-checkbox >{{printCheckbox(poll.limitedVote)}}</button> - </div> - </div> - <div class="form-group" ng-show="poll.limitedVote"> - <label class="col-lg-4 control-label" for="popMaxChoiceNumber">Nombre de vote :</label> - <div class="col-lg-6"> - <input type="text" class="form-control" id="popMaxChoiceNumber" ng-model="poll.maxChoiceNumber"/> - </div> - </div> - - <h4> Configuration des Réponses </h4> - - <div class="form-group"> - <label class="col-lg-4 control-label">Type : </label> - <div class="col-lg-8"> - <div class="btn-group"> - <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="1">Normal</button> - <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="2">Pourcentage</button> - <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="3">Condorcet</button> - <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="4">Nombre</button> - </div> - <div class="btn-group"> - <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="5">Borda</button> - <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="6">Vote alternatif</button> - <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="7">Coombs</button> - </div> - <p>Description du types de vote</p> - </div> - </div> - </div> - - <div class="form-group"> - <label class="col-lg-4 control-label">Visibilité : </label> - <div class="col-lg-8 btn-group"> - <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'EVERYBODY'">Public</button> - <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'VOTER'">Participants</button> - <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'CREATOR'">Créateur</button> - <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'ANONYMOUS'">Anonyme</button> - </div> - </div> - - <div class="form-group"> - <label class="col-lg-4 control-label">Autoriser les votes anonymes :</label> - <div class="col-lg-8"> - <button class="btn btn-default" ng-model="poll.anonymousVoteAllowed" btn-checkbox >{{printCheckbox(poll.anonymousVoteAllowed)}}</button> - </div> - </div> - - - <div class="modal-footer"> - <button type="button" class="btn btn-primary" ng-click="close()">close</button> - </div> -</form> \ No newline at end of file Copied: trunk/pollen-ui-angular/src/main/webapp/partials/poll-settings.html (from rev 3940, trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html) =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll-settings.html (rev 0) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-settings.html 2014-05-15 10:23:42 UTC (rev 3943) @@ -0,0 +1,151 @@ +<!-- + #%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% + --> + + + <h4>Confiuration global</h4> + + <div class="form-group"> + <label class="col-lg-4 control-label" for="beginDate">Date de début : </label> + <div class="col-lg-8"> + <input id="beginDate" class="form-control" type="text" + datepicker-popup="dd/MM/yyyy" + min-date="toDay" + max-date="data.poll.endDate" + ng-model="data.poll.beginDate" + is-open="beginDateOpened" + ng-click="beginDateOpened = true" /> + </div> + </div> + + <div class="form-group"> + <label class="col-lg-4 control-label" for="endDate">Date de fin : </label> + <div class="col-lg-8"> + <input id="endDate" class="form-control" type="text" + datepicker-popup="dd/MM/yyyy" + min-date="data.poll.beginDate" + ng-model="data.poll.endDate" + is-open="endDateOpened" + ng-click="endDateOpened = true" /> + </div> + </div> + + <div class="form-group"> + <label class="col-lg-4 control-label">Résultat : </label> + <div class="col-lg-8 btn-group"> + <button type="button" class="btn btn-success" ng-model="data.poll.resultVisibility" btn-radio="'EVERYBODY'">Public</button> + <button type="button" class="btn btn-success" ng-model="data.poll.resultVisibility" btn-radio="'VOTER'">Participants</button> + <button type="button" class="btn btn-success" ng-model="data.poll.resultVisibility" btn-radio="'CREATOR'">Créateur</button> + </div> + </div> + + <div class="form-group"> + <label class="col-lg-4 control-label">Résultat continue : </label> + <div class="col-lg-8 btn-group"> + <button class="btn btn-default" ng-model="data.poll.continuousResults" btn-radio="true">Oui</button> + <button class="btn btn-default" ng-model="data.poll.continuousResults" btn-radio="false">Non</button> + </div> + </div> + + <h4>Configuration des Choix</h4> + + <div class="form-group"> + <label class="col-lg-4 control-label">Ajout de choix par les votants :</label> + <div class="col-lg-8 btn-group"> + <button class="btn btn-default" ng-model="data.poll.choiceAddAllowed" btn-radio="true">Oui</button> + <button class="btn btn-default" ng-model="data.poll.choiceAddAllowed" btn-radio="false">Non</button> + </div> + </div> + + <div class="form-group" ng-show="data.poll.choiceAddAllowed"> + <label class="col-lg-4 control-label" for="beginChoiceDate">Date de début : </label> + <div class="col-lg-8"> + <input class="form-control" type="text" id="beginChoiceDate" + datepicker-popup="dd/MM/yyyy" + min-date="data.poll.beginDate" + max-date="data.poll.endChoiceDate" + ng-model="data.poll.beginChoiceDate" + is-open="beginChoiceDateOpened" + ng-click="beginChoiceDateOpened = true" /> + </div> + </div> + <div class="form-group" ng-if="data.poll.choiceAddAllowed" for="endChoiceDate"> + <label class="col-lg-4 control-label">Date de fin : </label> + <div class="col-lg-8"> + <input class="form-control" type="text" id="endChoiceDate" + datepicker-popup="dd/MM/yyyy" + min-date="data.poll.beginChoiceDate" + max-date="data.poll.endDate" + + ng-model="data.poll.endChoiceDate" + is-open="endChoiceDateOpened" + ng-click="endChoiceDateOpened = true" /> + </div> + </div> + + <div class="form-group"> + <label class="col-lg-4 control-label">Limiter les votes :</label> + <div class="col-lg-8 btn-group"> + <button class="btn btn-default" ng-model="data.poll.limitedVote" btn-radio="true">Oui</button> + <button class="btn btn-default" ng-model="data.poll.limitedVote" btn-radio="false">Non</button> + </div> + </div> + <div class="form-group" ng-show="data.poll.limitedVote"> + <label class="col-lg-4 control-label" for="popMaxChoiceNumber">Nombre de vote :</label> + <div class="col-lg-6"> + <input type="text" class="form-control" id="popMaxChoiceNumber" ng-model="data.poll.maxChoiceNumber"/> + </div> + </div> + + <h4> Configuration des Réponses </h4> + + <div class="form-group"> + <label class="col-lg-4 control-label">Type : </label> + <div class="col-lg-8"> + <div class="btn-group"> + <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="1">Normal</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="2">Pourcentage</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="3">Condorcet</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="4">Nombre</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="5">Borda</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="6">Vote alternatif</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteCountingType" btn-radio="7">Coombs</button> + </div> + <p>Description du types de vote</p> + </div> + </div> + + <div class="form-group"> + <label class="col-lg-4 control-label">Visibilité : </label> + <div class="col-lg-8 btn-group"> + <button type="button" class="btn btn-success" ng-model="data.poll.voteVisibility" btn-radio="'EVERYBODY'">Public</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteVisibility" btn-radio="'VOTER'">Participants</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteVisibility" btn-radio="'CREATOR'">Créateur</button> + <button type="button" class="btn btn-success" ng-model="data.poll.voteVisibility" btn-radio="'ANONYMOUS'">Anonyme</button> + </div> + </div> + + <div class="form-group"> + <label class="col-lg-4 control-label">Autoriser les votes anonymes :</label> + <div class="col-lg-8 btn-group"> + <button class="btn btn-default" ng-model="data.poll.anonymousVoteAllowed" btn-radio="true">Oui</button> + <button class="btn btn-default" ng-model="data.poll.anonymousVoteAllowed" btn-radio="false">Non</button> + </div> + </div> Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-14 14:09:23 UTC (rev 3942) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-15 10:23:42 UTC (rev 3943) @@ -19,7 +19,7 @@ #L% --> -<form class="form-inline" name="pollForm" novalidate> +<form class="form-horizontal"> <alert type="danger" ng-if="globalVariables.errorForm"> Champ non remplie </alert> <alert type="danger" ng-if="restError.choice"> Vous devez avoir au moins 1 choix </alert> @@ -60,7 +60,7 @@ </tab> <tab heading="Setting" ng-show="globalVariables.editMode" > - <div ng-include="'partials/poll-popupSettings.html'"></div> + <div ng-include="'partials/poll-settings.html'"></div> </tab> </tabset> @@ -68,14 +68,12 @@ <hr/> <button type="button" class="btn btn-default" ng-model="globalVariables.editMode" btn-checkbox>Mode Edition</button> <button class="btn btn-primary" ng-click="save()">Save</button> - <button class="btn btn-default" ng-click="popupSettings()">Settings</button> </div> <div ng-if="globalVariables.edit"> <hr/> <button type="button" class="btn btn-default" ng-model="globalVariables.editMode" btn-checkbox>Mode Edition</button> <button class="btn btn-danger" ng-click="delete();">Delete</button> - <button class="btn btn-default" ng-click="popupSettings()">Settings</button> </div> </form> \ No newline at end of file