r3921 - in trunk/pollen-ui-angular/src/main/webapp: js js/controllers partials
Author: garandel Date: 2014-05-07 18:20:20 +0200 (Wed, 07 May 2014) New Revision: 3921 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3921 Log: separate element of model in $scope.data Modified: 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-list.html trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 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-07 15:49:33 UTC (rev 3920) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-07 16:20:20 UTC (rev 3921) @@ -31,25 +31,26 @@ }, 5000); }); - $scope.poll = {}; + $scope.data = {}; + $scope.data.poll = {}; $scope.toHTML = function (data) { return $sce.trustAsHtml(data); } $scope.inlineVersion = function () { - $scope.poll.template = 'inline'; + $scope.data.poll.template = 'inline'; $scope.templateURL = './partials/inline-poll.html'; } $scope.bigVersion = function () { - $scope.poll.template = 'big'; + $scope.data.poll.template = 'big'; $scope.templateURL = './partials/big-poll.html'; } var initTemplateURL = function () { - if (angular.isDefined($scope.poll.template)) { - if ($scope.poll.template == "big") { + if (angular.isDefined($scope.data.poll.template)) { + if ($scope.data.poll.template == "big") { $scope.bigVersion(); } else { @@ -78,7 +79,7 @@ $scope.globalVariables.editMode = true; $scope.globalVariables.create = true; - $scope.globalVariables.voted = angular.isDefined($scope.poll.votants); + $scope.globalVariables.voted = angular.isDefined($scope.data.votants); $scope.globalVariables.lastType = 'TEXT'; $scope.globalVariables.lastDate = new Date(); @@ -88,8 +89,8 @@ }); $scope.addChoice = function () { - var index = $scope.poll.choice.push(initChoice()); - var choice = $scope.poll.choice[index-1]; + var index = $scope.data.choices.push(initChoice()); + var choice = $scope.data.choices[index-1]; popupChoice(choice, 'Add Choice'); } @@ -97,10 +98,10 @@ popupChoice(choice, 'Edit Choice'); } - var deleteChoice = function (ch) { - var index = $scope.poll.choice.indexOf(ch); + var deleteChoice = function (choice) { + var index = $scope.data.choices.indexOf(choice); if (index > -1) { - $scope.poll.choice.splice(index,1); + $scope.data.choices.splice(index,1); } } @@ -110,12 +111,12 @@ controller : PollPopChoiceCtrl, resolve : { title : function () { return title;}, - choice : function () { return choice; } + choice : function () { return choice;} } }); - modalInstance.result.then(function (ch) { - deleteChoice(ch); + modalInstance.result.then(function (choice) { + deleteChoice(choice); }, function () { $scope.globalVariables.lastType = choice.choiceType; $scope.globalVariables.lastDate = choice.date; @@ -128,7 +129,7 @@ controller : PollPopupSettingsCtrl, size : 'lg', resolve : { poll: function () { - return $scope.poll; + return $scope.data.poll; } } }); @@ -158,43 +159,41 @@ } var PollPopupSettingsCtrl = function ($scope, $filter, $modalInstance, poll) { - $scope.poll = poll; - $scope.toDay = new Date(); + $scope.data.poll = poll; + $scope.data.toDay = new Date(); - $scope.$watch('poll.beginDate', function() { - if (poll.beginChoiceDate) { - if (poll.beginChoiceDate < poll.beginDate) { - poll.beginChoiceDate = poll.beginDate; + $scope.$watch('data.poll.beginDate', function() { + if (data.poll.beginChoiceDate) { + if (data.poll.beginChoiceDate < data.poll.beginDate) { + data.poll.beginChoiceDate = data.poll.beginDate; } } else { - poll.beginChoiceDate = poll.beginDate; + data.poll.beginChoiceDate = data.poll.beginDate; } }); - $scope.$watch('poll.endDate', function() { - if (poll.endChoiceDate) { - if (poll.endChoiceDate > poll.endDate) { - poll.endChoiceDate = poll.endDate; + $scope.$watch('data.poll.endDate', function() { + if (data.poll.endChoiceDate) { + if (data.poll.endChoiceDate > data.poll.endDate) { + data.poll.endChoiceDate = data.poll.endDate; } } - /* else { - poll.endChoiceDate = poll.endDate; + data.poll.endChoiceDate = data.poll.endDate; } - */ }); if (!angular.isDefined($scope.poll.continuousResults)) { - $scope.poll.continuousResults = false; + $scope.data.poll.continuousResults = false; } if (!angular.isDefined($scope.poll.resultVisibility)) { - $scope.poll.resultVisibility = 'EVERYBODY'; + $scope.data.poll.resultVisibility = 'EVERYBODY'; } if (!angular.isDefined($scope.poll.choiceAddAllowed)) { - $scope.poll.choiceAddAllowed = false; + $scope.data.poll.choiceAddAllowed = false; } $scope.close = function () { @@ -213,22 +212,33 @@ }]) -.controller('PollCreateCtrl', ['$scope', '$controller', 'Poll', '$http', function ($scope, $controller, Poll, $http) { +.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', function ($scope, $controller, $location, Poll) { $controller('PollAdminCtrl', {$scope:$scope}); var initPoll = function () { - Poll.get({cmd:'new'}).$promise.then(function (poll) { - $scope.poll = poll; - $scope.poll.choice = []; - $scope.vote = {}; - $scope.vote.choice = $scope.poll.choice; - }) + Poll.get({cmd:'new'}, function (poll) { + $scope.data.poll = poll; + $scope.data.choices = []; + $scope.data.vote = {}; + $scope.data.vote.choices = $scope.data.choices; + $scope.restRequest = poll; + }); } initPoll(); $scope.save = function () { if ($scope.formValid) { - $scope.poll.$add(); + var poll = angular.copy($scope.data.poll); + poll.choice = angular.copy($scope.data.choices); + Poll.add(poll, function (data) { + $scope.globalVariables.saved = true; + $scope.globalVariables.restError = false; + $location.path('/poll/edit/'+data.topiaId); + }, function (error) { + $scope.globalVariables.restError = true; + $scope.restError = error; + } + ); } else { $scope.globalVariables.errorForm = true; @@ -236,7 +246,7 @@ } $scope.delete = function () { - $scope.poll = initPoll(); + $scope.data.poll = initPoll(); } }]) @@ -246,19 +256,19 @@ var initPoll = function () { Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) { - $scope.poll = poll; - PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) { - $scope.poll.choice = choices; - $scope.vote = {}; - $scope.vote.choice = $scope.poll.choice; - }); + $scope.data.poll = poll; }); + PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) { + $scope.data.choices = choices; + $scope.data.vote = {}; + $scope.data.vote.choices = $scope.data.choices; + }); } initPoll(); $scope.save = function () { if ($scope.formValid) { - $scope.poll.$update(function () { + $scope.data.poll.$update({permission:$scope.data.poll.creator.permission.token}, function () { $scope.globalVariables.saved = true; }); } @@ -269,53 +279,56 @@ } $scope.delete = function () { - $scope.poll.$delete(); - $location.path('/'); + $scope.data.poll.$delete({permission:$scope.data.poll.creator.permission.token}, function() { + $location.path('/'); + }); } }]) .controller('PollVoteCtrl', ['$scope', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', function ($scope, $filter, $controller, $routeParams, Poll, PollChoice) { $controller('PollCtrl', {$scope:$scope}); - Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) { - $scope.poll = poll; - PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) { - $scope.poll.choice = choices; - $scope.vote = {}; - $scope.vote.choice = $scope.poll.choice; + var initPoll = function () { + Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) { + $scope.data.poll = poll; }); - }); + PollChoice.query({pollId:$routeParams.pollId}, function (choices) { + $scope.data.choices = choices; + initVote(); + }); + } + initPoll(); $scope.globalVariables.editMode = false; - $scope.$watch('vote.name', function (newVal) { + $scope.$watch('data.vote.name', function (newVal) { if (newVal != '') { $scope.globalVariables.errorForm = false; } }); var initVote = function () { - $scope.vote = {}; - $scope.vote.name = ""; - $scope.vote.choice = []; - 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}); + $scope.data.vote = {}; + $scope.data.vote.name = ""; + $scope.data.vote.choices = []; + 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.choice[i].choiceType == 'DATE') { - $scope.vote.choice.push({name: $scope.poll.choice[i].date , value:false}); + else if ($scope.poll.choices[i].choiceType == 'DATE') { + $scope.data.choices.push({name: $scope.data.choices[i].date , value:false}); } } } $scope.voter = function () { - if ($scope.vote.name != '') { + if ($scope.data.vote.name != '') { var data = {}; - data.name = $scope.vote.name; - data.choice = angular.copy($scope.vote.choice); - if (!angular.isDefined($scope.poll.votants)) { - $scope.poll.votants = []; + data.name = $scope.data.vote.name; + data.choices = angular.copy($scope.data.vote.choices); + if (!angular.isDefined($scope.data.votants)) { + $scope.data.votants = []; } - $scope.poll.votants.push(data); + $scope.data.votants.push(data); // save vote @@ -332,7 +345,7 @@ .controller('PollListCtrl', ['$scope', '$controller', 'Poll', function ($scope, $controller, Poll) { $controller('PollCtrl', {$scope:$scope}); - $scope.polls = Poll.query(); + $scope.data.polls = Poll.query(); }]) Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-07 15:49:33 UTC (rev 3920) +++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-07 16:20:20 UTC (rev 3921) @@ -21,6 +21,7 @@ angular.module('pollenServices', ['ngResource']) .factory('BaseUrl', function() { + return 'http://localhost\\:8080/pollen-rest-api/v1'; }) @@ -41,15 +42,35 @@ transformRequest : function (data, headersGetter) { return transformParam(data); } + }, + 'delete' : { + method : 'DELETE' } }); }]) .factory('PollChoice', ['$resource', 'BaseUrl', function ($resource, BaseUrl) { + + var transformParam = function (data) { + var obj = angular.copy(data); + return 'choices='+JSON.stringify(obj); + }; + return $resource(BaseUrl+'/polls/:pollId/choices/:choiceId', {choiceId : '@topiaId'}, { - 'add' : { method:'POST'}, - 'update' : {method:'PUT'} + 'add' : { + method:'POST', + transformRequest : function (data, headersGetter) { + return transformParam(data); + } + }, + 'update' : + { + method:'PUT', + transformRequest : function (data, headersGetter) { + return transformParam(data); + } + } } ); }]) \ 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-07 15:49:33 UTC (rev 3920) +++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-07 16:20:20 UTC (rev 3921) @@ -25,7 +25,7 @@ <!-- 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"> + <td ng-repeat="choice in data.choices" class="pollChoice pollAnim" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> <div ng-if="choice.choiceType == 'TEXT'" edit-me="showEdit" > <div ng-hide="showEdit && !globalVariables.voted" class="fixe-input" title="{{choice.description}}">{{choice.name}} <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> <div ng-show="showEdit && !globalVariables.voted"> @@ -47,8 +47,8 @@ <!-- 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"> + <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> <td> @@ -58,9 +58,9 @@ <!-- end input vote --> <!-- begin print vote --> - <tr ng-repeat="vote in poll.votants track by $index" class="pollAnim"> + <tr ng-repeat="vote in data.votants track by $index" class="pollAnim"> <td class="pollChoice"> {{vote.name}}</td> - <td ng-repeat="choice in vote.choice" class="pollChoice"> + <td ng-repeat="choice in vote.choices" class="pollChoice"> <input type="checkbox" ng-model="choice.value" disabled/> </td> </tr> Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html 2014-05-07 15:49:33 UTC (rev 3920) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html 2014-05-07 16:20:20 UTC (rev 3921) @@ -1,5 +1,5 @@ -<div ng-repeat="poll in polls"> +<div ng-repeat="poll in data.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/> Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-07 15:49:33 UTC (rev 3920) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-07 16:20:20 UTC (rev 3921) @@ -22,6 +22,7 @@ <form class="form-inline" name="pollForm" novalidate> <alert type="danger" ng-if="globalVariables.errorForm"> Champ non remplie </alert> + <alert type="danger" ng-if="globalVariables.restError"> {{restError}} </alert> <alert type="success" ng-if="globalVariables.editMode && globalVariables.saved"> Sondage sauvegardé..</alert> <alert type="success" ng-if="!globalVariables.editMode && globalVariables.saved"> Vote effectué..</alert> @@ -29,16 +30,16 @@ <alert type="warning" ng-if="globalVariables.created"> <a href="#/poll/edit/{{pollId}}"> Edition du sondage </a>.. </alert> <div class="pollTitle" edit-me="showEditTitle"> - <h1 ng-hide="showEditTitle"> {{poll.title || 'Click Me for Editing'}} </h1> + <h1 ng-hide="showEditTitle"> {{data.poll.title || 'Click Me for Editing'}} </h1> - <h1 ng-show="showEditTitle"><input type="text" class="form-control" focus-me="showEditTitle" ng-model="poll.title" ng-exit="showEditTitle = false" required/></h1> + <h1 ng-show="showEditTitle"><input type="text" class="form-control" focus-me="showEditTitle" ng-model="data.poll.title" ng-exit="showEditTitle = false" required/></h1> </div> <div ng-hide="showEditDesc || !globalVariables.editMode && !poll.description " class="pollDesc" edit-me="showEditDesc"> - <div ng-bind-html="toHTML(poll.description || 'Description (Facultatif). Ce cadre disparait si aucune description n\'est mise')"></div> + <div ng-bind-html="toHTML(data.poll.description || 'Description (Facultatif). Ce cadre disparait si aucune description n\'est mise')"></div> </div> <div ng-show="showEditDesc" class="pollDesc " ng-exit="showEditDesc = false;"> - <textarea id="descEditor" data-ck-editor ng-model="poll.description"></textarea> + <textarea id="descEditor" data-ck-editor ng-model="data.poll.description"></textarea> <input type="button" value="Return" class="btn btn-primary" ng-click="showEditDesc = false;"/> </div>
participants (1)
-
garandel@users.chorem.org