r3950 - in trunk/pollen-ui-angular/src/main/webapp: . js js/controllers partials
Author: garandel Date: 2014-05-15 17:06:28 +0200 (Thu, 15 May 2014) New Revision: 3950 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3950 Log: vote persistant Modified: trunk/pollen-ui-angular/src/main/webapp/index.html 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/index.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-15 14:06:25 UTC (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-15 15:06:28 UTC (rev 3950) @@ -28,10 +28,10 @@ <script src="js/conf.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script> - <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> - <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script> - <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-resource.min.js"></script> - <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-cookies.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-route.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-resource.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-cookies.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootstrap-tpls.min.js"></script> <script src="js/libs/ckeditor/ckeditor.js"></script> 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-15 14:06:25 UTC (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-15 15:06:28 UTC (rev 3950) @@ -111,6 +111,7 @@ } var popupChoice = function (choice, title, callBack) { + var oldChoice = angular.copy(choice); var modalInstance = $modal.open({ templateUrl : 'partials/poll-popupChoice.html', controller : PollPopChoiceCtrl, @@ -125,7 +126,11 @@ }, function () { $scope.globalVariables.lastType = choice.choiceType; $scope.globalVariables.lastDate = choice.date; - callBack(choice); + console.log(oldChoice); + console.log(choice); + if (!angular.equals(oldChoice, choice)) { + callBack(choice); + } }); } @@ -288,30 +293,34 @@ $scope.data.choices = choices; initVote(); }); + PollVote.query({pollId:$routeParams.pollId}, function (votes) { + $scope.data.votants = votes; + angular.forEach($scope.data.votants, function (vote) { + angular.forEach(vote.choice, function (choice) { + if (choice.voteValue != null && choice.voteValue != 0) { + choice.voteValue = true; + } + else { + choice.voteValue = false; + } + }) + }) + }) } initPoll(); $scope.globalVariables.editMode = false; - $scope.$watch('data.vote.name', function (newVal) { - if (newVal != '') { - $scope.globalVariables.errorForm = false; - } - }); var initVote = function () { $scope.data.vote = {}; $scope.data.vote.voter = {name : ""}; $scope.data.vote.anonymous = false; - $scope.data.vote.voteToChoices = []; + $scope.data.vote.choice = []; for (var i = 0; i < $scope.data.choices.length; ++i) { - $scope.data.vote.voteToChoices.push({choiceId:$scope.data.choices[i].topiaId, voteValue:false}); + $scope.data.vote.choice.push({choiceId:$scope.data.choices[i].topiaId, voteValue:1}); } } - PollVote.query({pollId:$routeParams.pollId}, function (data) { - $scope.data.votants = data; - }) - $scope.voter = function () { if ($scope.data.vote.name != '') { PollVote.add({pollId:$routeParams.pollId}, $scope.data.vote, function (returnRequest) { Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-15 14:06:25 UTC (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-15 15:06:28 UTC (rev 3950) @@ -67,6 +67,15 @@ .factory('PollVote', ['$resource', function ($resource) { var transformParam = function (data) { + angular.forEach(data.choice, function (choice) { + delete choice.$$hashKey; + if (choice.voteValue != null && !choice.voteValue) { + choice.voteValue = 1; + } + else { + choice.voteValue = 0; + } + }); return 'vote='+encodeURIComponent(JSON.stringify(data)); }; 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-15 14:06:25 UTC (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-15 15:06:28 UTC (rev 3950) @@ -51,8 +51,8 @@ <!-- begin input vote --> <tr ng-show="!globalVariables.editMode"> <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 ng-repeat="choice in data.vote.choice" 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()" /> @@ -62,11 +62,10 @@ <!-- begin print vote --> <tr ng-repeat="vote in data.votants track by $index" class="pollAnim" ng-show="!globalVariables.editMode"> - <td class="pollChoice"> {{vote.name}}</td> - <td ng-repeat="choice in vote.choices" class="pollChoice"> - <input type="checkbox" ng-model="choice.value" disabled/> + <td class="pollChoice"> {{vote.voter.name}}</td> + <td ng-repeat="choice in vote.choice" class="pollChoice"> + <input type="checkbox" ng-model="choice.voteValue" disabled /> </td> </tr> <!-- end print vote --> </table> - Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-15 14:06:25 UTC (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-15 15:06:28 UTC (rev 3950) @@ -19,7 +19,7 @@ #L% --> -<form class="form-horizontal"> +<form class="form-horizontal" novalidate> <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>
participants (1)
-
garandelï¼ users.chorem.org