Author: garandel Date: 2014-05-05 11:38:12 +0200 (Mon, 05 May 2014) New Revision: 3911 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3911 Log: separate controllers editing and adding poll 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/partials/big-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-05 09:17:44 UTC (rev 3910) +++ trunk/pollen-ui-angular/src/main/webapp/css/style.css 2014-05-05 09:38:12 UTC (rev 3911) @@ -184,4 +184,9 @@ .pollBigChoice .pollChoiceInput { margin-top:20px; text-align:center; +} + +.pollBigVote { + float:right; + margin-top:5px; } \ 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-05 09:17:44 UTC (rev 3910) +++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-05 09:38:12 UTC (rev 3911) @@ -66,8 +66,8 @@ .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', {templateUrl: './partials/home.html', controller: "HomeCtrl"}) - .when('/poll/create', {templateUrl: './partials/poll.html', controller: "PollAdminCtrl"}) - .when('/poll/edit/:pollId', {templateUrl: './partials/poll.html', controller:"PollAdminCtrl"}) + .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/list', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) .otherwise({redirectTo: '/'}); 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:17:44 UTC (rev 3910) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-05 09:38:12 UTC (rev 3911) @@ -22,7 +22,7 @@ }]) -.controller('PollCtrl', ['$scope', '$sce', '$timeout', 'pollStorage', function ($scope, $sce, $timeout, pollStorage) { +.controller('PollCtrl', ['$scope', '$sce', '$timeout', function ($scope, $sce, $timeout) { $scope.globalVariables = {saved:false}; $scope.$watch('globalVariables.saved', function() { $timeout(function () { @@ -64,20 +64,9 @@ }]) -.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'PollsRest', '$http', 'pollStorage', function ($scope, $controller, $modal, $filter, $timeout, PollsRest, $http, pollStorage) { +.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'Restangular', '$http', function ($scope, $controller, $modal, $filter, $timeout, Restangular, $http) { $controller('PollCtrl', {$scope:$scope}); - var initPoll = function () { - - PollsRest.one('new').get().then(function (skeletonPoll) { - $scope.poll = skeletonPoll; - $scope.poll.choice = []; - $scope.vote = {}; - $scope.vote.choice = $scope.poll.choice; - - }); - } - var initChoice = function () { return { name: '', @@ -95,14 +84,6 @@ $scope.globalVariables.errorForm = false; }); - if (!angular.isDefined($scope.poll.choice)) { - initPoll(); - } - else { - $scope.vote = {}; - $scope.vote.choice = $scope.poll.choice; - } - $scope.addChoice = function () { var index = $scope.poll.choice.push(initChoice()); var choice = $scope.poll.choice[index-1]; @@ -142,7 +123,10 @@ 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; }); @@ -190,6 +174,38 @@ } }]) +.controller('PollCreateCtrl', ['$scope', '$controller', 'Restangular', function ($scope, $controller, Restangular) { + $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; + }); + } + initPoll(); + +}]) + +.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', 'Restangular', function ($scope, $controller, $routeParams, Restangular) { + $controller('PollAdminCtrl', {$scope:$scope}); + + var initPoll = function () { + + 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; + $scope.vote = {}; + $scope.vote.choice = $scope.poll.choice; + }); + }); + } + initPoll(); +}]) + .controller('PollVoteCtrl', ['$scope', '$filter', '$controller', 'Restangular', 'pollStorage', function ($scope, $filter, $controller, Restangular, pollStorage) { $controller('PollCtrl', {$scope:$scope}); Modified: trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html 2014-05-05 09:17:44 UTC (rev 3910) +++ trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html 2014-05-05 09:38:12 UTC (rev 3911) @@ -21,11 +21,11 @@ ~ --> -<div ng-repeat="choice in poll.choices" class="row pollBigChoice"> +<div ng-repeat="choice in poll.choice" class="row pollBigChoice"> <div class="col-sm-10"> <div ng-click="showChoiceDesc = !showChoiceDesc" > - <div ng-if="choice.type == 'TEXT'"> + <div ng-if="choice.choiceType == 'TEXT'"> <h3 edit-me="showEdit" ng-hide="showEdit" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> <button class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)">...</button> {{choice.name}} @@ -35,7 +35,7 @@ </h3> </div> - <div ng-if="choice.type == 'DATE'"> + <div ng-if="choice.choiceType == 'DATE'"> <h3 edit-me="showEdit" ng-hide="showEdit || isOpen" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> <button class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)">...</button> {{choice.date | date:'dd/MM/yyyy'}} @@ -49,7 +49,7 @@ <p ng-show="globalVariables.editMode && showEditChoiceDesc"><textarea ng-model="choice.description" focus-me="showEditChoiceDesc" ng-exit="showEditChoiceDesc = false" cols="80" rows="8"></textarea></p> </div> <div class="col-sm-2 pollChoiceInput"> - <input type="checkbox" ng-model="vote.choices[$index].value"/> + <input type="checkbox" ng-model="vote.choice[$index].value"/> </div> </div> <div class="row pollBigChoice" ng-if="globalVariables.editMode"> @@ -61,7 +61,7 @@ </div> </div> -<div style="float:right; margin-top:5px;"> +<div class="pollBigVote"> <input type="text" placeholder="Votre Nom" ng-model="vote.name"/> <button class="btn btn-primary" ng-click="voter()">Voter</button> </div> \ No newline at end of file