From garandel@users.chorem.org Thu May 15 17:06:29 2014 From: garandel@users.chorem.org To: pollen-commits@list.chorem.org Subject: [Pollen-commits] r3950 - in trunk/pollen-ui-angular/src/main/webapp: . js js/controllers partials Date: Thu, 15 May 2014 17:06:29 +0200 Message-ID: <20140515150629.248A2181DA3@goh.codelutin.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7847574279778846239==" --===============7847574279778846239== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-15 14:06:25 UT= C (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-15 15:06:28 UT= C (rev 3950) @@ -28,10 +28,10 @@ =20 - - - - + + + + =20 Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-0= 5-15 14:06:25 UTC (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-0= 5-15 15:06:28 UTC (rev 3950) @@ -111,6 +111,7 @@ } =20 var popupChoice =3D function (choice, title, callBack) { + var oldChoice =3D angular.copy(choice); var modalInstance =3D $modal.open({ templateUrl : 'partials/poll-popupChoice.html', controller : PollPopChoiceCtrl, @@ -125,7 +126,11 @@ }, function () { $scope.globalVariables.lastType =3D choice.choiceType; $scope.globalVariables.lastDate =3D choice.date; - callBack(choice); + console.log(oldChoice); + console.log(choice); + if (!angular.equals(oldChoice, choice)) { + callBack(choice); + } }); } =20 @@ -288,30 +293,34 @@ $scope.data.choices =3D choices; initVote(); }); + PollVote.query({pollId:$routeParams.pollId}, function (votes) { + $scope.data.votants =3D votes; + angular.forEach($scope.data.votants, function (vote) { + angular.forEach(vote.choice, function (choice) { + if (choice.voteValue !=3D null && choice.voteValue !=3D 0) { + choice.voteValue =3D true; + } + else { + choice.voteValue =3D false; + } + }) + }) + }) } initPoll(); =20 $scope.globalVariables.editMode =3D false; - $scope.$watch('data.vote.name', function (newVal) { - if (newVal !=3D '') { - $scope.globalVariables.errorForm =3D false; - } - }); =20 var initVote =3D function () { $scope.data.vote =3D {}; $scope.data.vote.voter =3D {name : ""}; $scope.data.vote.anonymous =3D false; - $scope.data.vote.voteToChoices =3D []; + $scope.data.vote.choice =3D []; for (var i =3D 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].topiaI= d, voteValue:1}); } } =20 - PollVote.query({pollId:$routeParams.pollId}, function (data) { - $scope.data.votants =3D data; - }) - $scope.voter =3D function () { if ($scope.data.vote.name !=3D '') { PollVote.add({pollId:$routeParams.pollId}, $scope.data.vote, function = (returnRequest) { Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-15 14:06:2= 5 UTC (rev 3949) +++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-15 15:06:2= 8 UTC (rev 3950) @@ -67,6 +67,15 @@ =20 .factory('PollVote', ['$resource', function ($resource) { var transformParam =3D function (data) { + angular.forEach(data.choice, function (choice) { + delete choice.$$hashKey; + if (choice.voteValue !=3D null && !choice.voteValue) { + choice.voteValue =3D 1; + } + else { + choice.voteValue =3D 0; + } + }); return 'vote=3D'+encodeURIComponent(JSON.stringify(data)); }; =20 Modified: trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 @@