r3913 - in trunk/pollen-ui-angular/src/main/webapp: . js js/controllers partials
Author: garandel Date: 2014-05-05 14:36:59 +0200 (Mon, 05 May 2014) New Revision: 3913 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3913 Log: Add list of polls for edit and vote (no security) Added: trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html Modified: trunk/pollen-ui-angular/src/main/webapp/index.html 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/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-05 09:43:49 UTC (rev 3912) +++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-05 12:36:59 UTC (rev 3913) @@ -46,7 +46,7 @@ <div class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li><a href="#/poll/create">Creer</a></li> - <li><a href="#/poll/vote">Voter</a></li> + <li><a href="#/poll/list">Liste</a></li> </ul> </div> </div> Modified: trunk/pollen-ui-angular/src/main/webapp/js/app.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-05 09:43:49 UTC (rev 3912) +++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-05 12:36:59 UTC (rev 3913) @@ -68,7 +68,7 @@ $routeProvider.when('/', {templateUrl: './partials/home.html', controller: "HomeCtrl"}) .when('/poll/create', {templateUrl: './partials/poll.html', controller: "PollCreateCtrl"}) .when('/poll/edit/:pollId', {templateUrl: './partials/poll.html', controller:"PollEditCtrl"}) - .when('/poll/vote', {templateUrl: './partials/poll.html', controller :"PollVoteCtrl"}) + .when('/poll/vote/:pollId', {templateUrl: './partials/poll.html', controller :"PollVoteCtrl"}) .when('/poll/list', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) .otherwise({redirectTo: '/'}); @@ -103,11 +103,11 @@ restrict:'A', link: function ($scope, element, attrs) { element.bind('click', function () { - if ($scope.globalVariables.editMode) { - $scope.$apply(function () { - $scope[attrs.editMe] = true; - $scope.globalVariables.saved = false; - }); + if ($scope.globalVariables.editMode) { + $scope.$apply(function () { + $scope[attrs.editMe] = true; + $scope.globalVariables.saved = false; + }); } }); } @@ -152,18 +152,3 @@ }; }) -.factory('pollStorage', function () { - var storageId='poll-storage'; - return { - get: function () { - return JSON.parse(localStorage.getItem(storageId) || '{}'); - }, - put: function (data) { - localStorage.setItem(storageId, JSON.stringify(data)); - }, - remove: function () { - localStorage.setItem(storageId, '{}'); - } - } -}); - 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-05 09:43:49 UTC (rev 3912) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-05 12:36:59 UTC (rev 3913) @@ -18,7 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollControllers', []).controller('HomeCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) { +angular.module('pollControllers', []) +.controller('HomeCtrl', ['$scope', function ($scope) { }]) @@ -70,6 +71,7 @@ var initChoice = function () { return { name: '', + date: $scope.globalVariables.lastDate, choiceType: $scope.globalVariables.lastType }; } @@ -78,6 +80,7 @@ $scope.globalVariables.create = true; $scope.globalVariables.voted = angular.isDefined($scope.poll.votants); $scope.globalVariables.lastType = 'TEXT'; + $scope.globalVariables.lastDate = new Date(); $scope.$watch('pollForm.$valid', function (newVal) { $scope.formValid = newVal; @@ -101,7 +104,6 @@ } } - var popupChoice = function (choice, title) { var modalInstance = $modal.open({ templateUrl : 'partials/poll-popupChoice.html', @@ -116,27 +118,10 @@ deleteChoice(ch); }, function () { $scope.globalVariables.lastType = choice.choiceType; + $scope.globalVariables.lastDate = choice.date; }); } - $scope.save = function () { - if ($scope.formValid) { - var data = {}; - data.poll = $scope.poll; - -// Restangular.all('polls').post('polls', data).then(function (data) {; - $http.post('http://localhost:8080/pollen-rest-api/v1/polls', data).success(function (data) { - $scope.test = data; - $scope.globalVariables.saved = true; - }); - - } - else { - $scope.globalVariables.errorForm = true; - } - - } - $scope.reset = function () { $scope.poll = initPoll(); $scope.voteChoice = $scope.poll.choice; @@ -172,24 +157,45 @@ } } + + + }]) -.controller('PollCreateCtrl', ['$scope', '$controller', 'Restangular', function ($scope, $controller, Restangular) { +.controller('PollCreateCtrl', ['$scope', '$controller', 'Restangular', '$http', function ($scope, $controller, Restangular, $http) { $controller('PollAdminCtrl', {$scope:$scope}); - var initPoll = function () { - Restangular.service('polls').one('new').get().then(function (skeletonPoll) { - $scope.poll = skeletonPoll; - $scope.poll.choice = []; - $scope.vote = {}; - $scope.vote.choice = $scope.poll.choice; + var initPoll = function () { + Restangular.service('polls').one('new').get().then(function (skeletonPoll) { + $scope.poll = skeletonPoll; + $scope.poll.choice = []; + $scope.vote = {}; + $scope.vote.choice = $scope.poll.choice; + }); + } + initPoll(); + + $scope.save = function () { + if ($scope.formValid) { + var data = {}; + data.poll = $scope.poll; + +// Restangular.all('polls').post('polls', data).then(function (data) {; + $http.post('http://localhost:8080/pollen-rest-api/v1/polls', data).success(function (data) { + $scope.test = data; + $scope.globalVariables.saved = true; }); + } - initPoll(); + else { + $scope.globalVariables.errorForm = true; + } + } + }]) -.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', 'Restangular', function ($scope, $controller, $routeParams, Restangular) { +.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', 'Restangular', '$http', function ($scope, $controller, $routeParams, Restangular, $http) { $controller('PollAdminCtrl', {$scope:$scope}); var initPoll = function () { @@ -204,17 +210,37 @@ }); } initPoll(); + + $scope.save = function () { + if ($scope.formValid) { + var data = {}; + data.poll = $scope.poll; + +// Restangular.all('polls').post('polls', data).then(function (data) {; + $http.put('http://localhost:8080/pollen-rest-api/v1/polls/'+$routeParams.pollId, data).success(function (data) { + $scope.test = data; + $scope.globalVariables.saved = true; + }); + + } + else { + $scope.globalVariables.errorForm = true; + } + + } }]) -.controller('PollVoteCtrl', ['$scope', '$filter', '$controller', 'Restangular', 'pollStorage', function ($scope, $filter, $controller, Restangular, pollStorage) { +.controller('PollVoteCtrl', ['$scope', '$filter', '$controller', '$routeParams', 'Restangular', function ($scope, $filter, $controller, $routeParams, Restangular) { $controller('PollCtrl', {$scope:$scope}); - Restangular.one('polls').get().then(function (poll) { - $scope.poll = poll[0]; + Restangular.one('polls', $routeParams.pollId).get().then(function (poll) { + $scope.poll = poll; + Restangular.one('polls', $routeParams.pollId).all('choices').getList().then(function (choices) { + $scope.poll.choice = choices; + initVote(); + }) + }); - initVote(); - }) - $scope.globalVariables.editMode = false; $scope.$watch('vote.ame', function (newVal) { if (newVal != '') { @@ -226,12 +252,12 @@ $scope.vote = {}; $scope.vote.name = ""; $scope.vote.choice = []; - for (var i = 0; i < $scope.poll.choices.length; ++i) { - if ($scope.poll.choices[i].choiceType == 'text') { - $scope.vote.choices.push({name:$scope.poll.choice[i].name, value:false}); + for (var i = 0; i < $scope.poll.choice.length; ++i) { + if ($scope.poll.choice[i].choiceType == 'TEXT') { + $scope.vote.choice.push({name:$scope.poll.choice[i].name, value:false}); } - else if ($scope.poll.choices[i].choiceType == 'date') { - $scope.vote.choices.push({name: $scope.poll.choice[i].date , value:false}); + else if ($scope.poll.choice[i].choiceType == 'DATE') { + $scope.vote.choice.push({name: $scope.poll.choice[i].date , value:false}); } } } @@ -245,7 +271,9 @@ $scope.poll.votants = []; } $scope.poll.votants.push(data); - pollStorage.put($scope.poll); + + // save vote + $scope.globalVariables.saved = true; $scope.globalVariables.errorForm = false; initVote(); @@ -256,8 +284,12 @@ } }]) -.controller('PollListCtrl', ['$scope', 'pollStorage', function ($scope, pollStorage) { +.controller('PollListCtrl', ['$scope', '$controller', 'Restangular', function ($scope, $controller, Restangular) { + $controller('PollCtrl', {$scope:$scope}); + Restangular.all('polls').getList().then(function (polls) { + $scope.polls = polls; + }); }]) ; \ No newline at end of file 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-05 09:43:49 UTC (rev 3912) +++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-05 12:36:59 UTC (rev 3913) @@ -22,6 +22,7 @@ --> <table> +<!-- begin print choices --> <tr> <td><button ng-if="globalVariables.editMode" ng-click="bigVersion()" class="btn btn-default" >Big version</button></td> <td ng-repeat="choice in poll.choice" class="pollChoice pollAnim" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> @@ -42,7 +43,9 @@ </td> <td ng-if="!globalVariables.voted && globalVariables.editMode"><input type="button" class="btn btn-default btn-large" value="+" ng-click="addChoice()"/></td> </tr> +<!-- end print choice --> +<!-- begin input vote --> <tr> <td class="pollChoice"> <input type="text" class="form-control" placeholder="votre nom" ng-model="vote.name" /> </td> <td ng-repeat="choice in vote.choice" class="pollChoice"> @@ -52,12 +55,15 @@ <input class="btn btn-primary btn-large" type="button" value="Vote" ng-click="voter()" /> </td> </tr> +<!-- end input vote --> +<!-- begin print vote --> <tr ng-repeat="vote in poll.votants track by $index" class="pollAnim"> <td class="pollChoice"> {{vote.name}}</td> - <td ng-repeat="choice in vote.choices" class="pollChoice"> + <td ng-repeat="choice in vote.choice" class="pollChoice"> <input type="checkbox" ng-model="choice.value" disabled/> </td> </tr> +<!-- end print vote --> </table> Added: trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html (rev 0) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html 2014-05-05 12:36:59 UTC (rev 3913) @@ -0,0 +1,6 @@ + +<div ng-repeat="poll in polls"> + <h2><a href="#/poll/vote/{{poll.topiaId}}">{{poll.title}}</a> <a href="#/poll/edit/{{poll.topiaId}}"><i class="glyphicon glyphicon-pencil"></i></a></h2> + <p ng-bind-html="toHTML(poll.description)"></p> + <hr/> +</div> \ No newline at end of file Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-05 09:43:49 UTC (rev 3912) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-05 12:36:59 UTC (rev 3913) @@ -23,7 +23,7 @@ <alert type="'danger'" ng-if="globalVariables.errorForm"> Champ non remplie </alert> <alert type="'success'" ng-if="globalVariables.editMode && globalVariables.saved"> Sondage sauvegardé..</alert> - <alert type="'success'" ng-if="!globalVariables.editMode && globalVariables.saved"> Vote effectué.. <pre>{{rest}}</pre></alert> + <alert type="'success'" ng-if="!globalVariables.editMode && globalVariables.saved"> Vote effectué..</alert> <alert type="'warning'" ng-if="globalVariables.voted"> Les votes ont commencé, certaine modification sont inaccessible.. </alert>
participants (1)
-
garandel@users.chorem.org