This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit 5deacbbbec104a36ae359d8cb6599b6d2f6f37bd Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jul 30 15:32:46 2014 +0200 can edit and add choice in page of vote --- .../src/main/webapp/js/controllers/pollCtrl.js | 305 ++++++++++++--------- .../src/main/webapp/partials/inline-poll.html | 16 +- 2 files changed, 179 insertions(+), 142 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js index f6d6b4f..7da43e7 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -26,6 +26,10 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr Poll.skeletonNew(); }]) +////////////////////////////////// +// Poll global controller // +////////////////////////////////// + .controller('PollCtrl', ['$scope', '$rootScope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', '$translate', '$route', '$q', 'Poll', 'PollenResource', 'Page', 'DateFormat', function ( $scope, $rootScope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage, $translate, $route, $q, Poll, PollenResource, Page, DateFormat) { @@ -325,72 +329,20 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }]) -.controller('PollAdminCtrl', ['$scope', '$rootScope', '$controller', '$modal', '$timeout', '$routeParams', 'Poll', - function ($scope, $rootScope, $controller, $modal, $timeout, $routeParams, Poll) { - if (angular.isUndefined($scope.globalVariables)) { - $scope.globalVariables = {}; - } - - $scope.globalVariables.editMode = true; - //$scope.globalVariables.voted = angular.isDefined($scope.data.votants); - $scope.globalVariables.lastType = 'TEXT'; - $scope.globalVariables.lastDate = null; - $scope.restError = {}; - - //////////////////////////////// - //// VOTER LIST ///// - //////////////////////////////// - - var newMember = function () { - return {name:'', email:'', weight:1.0}; - } - - var newGroup = function () { - var members = []; - for (var j = 0; j < 3; j++) { - members.push(newMember()); - } - return {group:{name:'', weight:1.0}, members:members} - } - - $scope.data.voterList = []; - $scope.data.voterList.push(newGroup()); - - $timeout(function () { - $scope.$watch('data.poll.pollType', function (newVal, oldVal) { - if (newVal != oldVal && newVal == 'RESTRICTED') { - var listMember = []; - for (var i = 0; i < $scope.data.voterList.length; i++) { - for (var j = 0; j < $scope.data.voterList[i].members.length; j++) { - // check if not a empty line - if ($scope.data.voterList[i].members[j].email != '' || $scope.data.voterList[i].members[j].name != '') { - listMember.push($scope.data.voterList[i].members[j]); - } - } - } - // get the first group - $scope.data.voterList = $scope.data.voterList.splice(0,1); +////////////////////////////////// +// Admin choice controller // +////////////////////////////////// - // check if one voter is enter in one group - if (listMember.length > 0) { - $scope.data.voterList[0].members = listMember; - } - } - }); - }); - - $scope.addVoter = function (index) { - $scope.data.voterList[index].members.push(newMember()); - } +.controller('PollAdminChoiceCtrl', ['$scope', '$rootScope', '$modal', '$routeParams', 'PollChoice', + function ($scope, $rootScope, $modal, $routeParams, PollChoice) { - $scope.addGroup = function () { - $scope.data.voterList.push(newGroup()); + if (angular.isUndefined($scope.globalVariables)) { + $scope.globalVariables = {}; } - //////////////////////////////// - //// CHOICE ///// - //////////////////////////////// + $scope.globalVariables.lastType = 'TEXT'; + $scope.globalVariables.lastDate = null; var initChoice = function () { return { @@ -408,21 +360,82 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr popupChoice(choice, 'Ajout d\'un Choix', $scope.callBackAddChoice); } - $scope.callBackAddChoice = function (choice) {} - $scope.editChoice = function (choice) { popupChoice(choice, 'Edition du Choix', $scope.callBackEditChoice); } - $scope.callBackEditChoice = function (choice) {} + + $scope.callBackAddChoice = function (choice) { + if (angular.isDefined($routeParams.pollId)) { + var saveChoice = angular.copy(choice); + + saveChoice = $scope.preSendChoice(saveChoice); + + PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, saveChoice, function (data) { + delete choice.restError; + choice.id = data.id; + choice.permission = data.permission; + $rootScope.$broadcast('newSuccess', 'poll.saved'); + }, function (error) { + choice.restError = error.data; + }); + } + } + + $scope.callBackEditChoice = function (choice) { + if (angular.isDefined($routeParams.pollId)) { + var saveChoice = angular.copy(choice); + + saveChoice = $scope.preSendChoice(saveChoice); + + PollChoice.update({pollId:$routeParams.pollId, permission:choice.permission}, saveChoice, function() { + delete choice.restError; + $rootScope.$broadcast('newSuccess', 'poll.saved'); + }, function (error) { + choice.restError = error.data; + }); + } + } $scope.deleteChoice = function (choice) { + if (angular.isDefined($routeParams.pollId)) { + PollChoice.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken, choiceId: choice.id}, function () { + $rootScope.$broadcast('newSuccess', 'poll.saved'); + deleteChoice(choice); + }, function (error) { + if (error.status == 400) { + angular.extend($scope.restError, error.data); + if (angular.isDefined(error.data.choice)) { + $rootScope.$broadcast('newError', error.data.choice[0]); + } + } + else { + deleteChoice(choice); + } + }); + } else { + deleteChoice(choice); + } + }; + + var deleteChoice = function (choice) { var index = $scope.data.choices.indexOf(choice); if (index > -1) { $scope.data.choices.splice(index,1); } } + $scope.saveChoice = function (choice) { + if (angular.isDefined(choice)) { + if (angular.isDefined(choice.id) && choice.id != null) { + $scope.callBackEditChoice(choice); + } + else { + $scope.callBackAddChoice(choice); + } + } + } + var popupChoice = function (choiceEdit, title, callBack) { var choice = angular.copy(choiceEdit); @@ -546,12 +559,74 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr } - $scope.printCheckbox= function (value) { - if (value) { - return 'Oui'; - } else { - return 'Non'; +}]) + + +////////////////////////////////// +// Admin poll controller // +////////////////////////////////// + +.controller('PollAdminCtrl', ['$scope', '$rootScope', '$controller', '$timeout', '$routeParams', 'Poll', + function ($scope, $rootScope, $controller, $timeout, $routeParams, Poll) { + $controller('PollAdminChoiceCtrl', {$scope:$scope}); + + + if (angular.isUndefined($scope.globalVariables)) { + $scope.globalVariables = {}; + } + + $scope.globalVariables.editMode = true; + $scope.restError = {}; + + //////////////////////////////// + //// VOTER LIST ///// + //////////////////////////////// + + var newMember = function () { + return {name:'', email:'', weight:1.0}; + } + + var newGroup = function () { + var members = []; + for (var j = 0; j < 3; j++) { + members.push(newMember()); } + return {group:{name:'', weight:1.0}, members:members} + } + + $scope.data.voterList = []; + $scope.data.voterList.push(newGroup()); + + $timeout(function () { + $scope.$watch('data.poll.pollType', function (newVal, oldVal) { + if (newVal != oldVal && newVal == 'RESTRICTED') { + var listMember = []; + for (var i = 0; i < $scope.data.voterList.length; i++) { + for (var j = 0; j < $scope.data.voterList[i].members.length; j++) { + // check if not a empty line + if ($scope.data.voterList[i].members[j].email != '' || $scope.data.voterList[i].members[j].name != '') { + listMember.push($scope.data.voterList[i].members[j]); + } + } + } + + // get the first group + $scope.data.voterList = $scope.data.voterList.splice(0,1); + + // check if one voter is enter in one group + if (listMember.length > 0) { + $scope.data.voterList[0].members = listMember; + } + } + }); + }); + + $scope.addVoter = function (index) { + $scope.data.voterList[index].members.push(newMember()); + } + + $scope.addGroup = function () { + $scope.data.voterList.push(newGroup()); } //////////////////////////////// @@ -586,6 +661,11 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }); }]) + +////////////////////////////////// +// Admin create poll controller // +////////////////////////////////// + .controller('PollCreateCtrl', ['$scope', '$rootScope', '$controller', '$location', 'Poll', 'SessionStorage', 'PollVoterList', 'Page', function ( $scope, $rootScope, $controller, $location, Poll, SessionStorage, PollVoterList, Page) { $controller('PollCtrl', {$scope:$scope}); @@ -664,6 +744,10 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }]) +////////////////////////////////// +// Admin edit poll controller // +////////////////////////////////// + .controller('PollEditCtrl', ['$scope', '$rootScope', '$controller', '$routeParams', '$location', '$timeout', '$translate', 'Poll', 'PollChoice', 'PollVote', 'PollVoterList', 'PollVoterListMember', 'FavoriteList', 'SessionStorage', 'Page', function ( $scope, $rootScope, $controller, $routeParams, $location, $timeout, $translate, Poll, PollChoice, PollVote, PollVoterList, PollVoterListMember, FavoriteList, SessionStorage, Page) { $controller('PollAdminCtrl', {$scope:$scope}); @@ -671,71 +755,6 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr Page.setTitle('title.poll.edit'); //////////////////////////////// - //// CHOICE ///// - //////////////////////////////// - - $scope.callBackAddChoice = function (choice) { - var saveChoice = angular.copy(choice); - - saveChoice = $scope.preSendChoice(saveChoice); - - PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, saveChoice, function (data) { - delete choice.restError; - choice.id = data.id; - $rootScope.$broadcast('newSuccess', 'poll.saved'); - }, function (error) { - choice.restError = error.data; - }); - } - - $scope.callBackEditChoice = function (choice) { - var saveChoice = angular.copy(choice); - - saveChoice = $scope.preSendChoice(saveChoice); - - PollChoice.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, saveChoice, function() { - delete choice.restError; - $rootScope.$broadcast('newSuccess', 'poll.saved'); - }, function (error) { - choice.restError = error.data; - }); - } - - $scope.deleteChoice = function (choice) { - PollChoice.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken, choiceId: choice.id}, function () { - $rootScope.$broadcast('newSuccess', 'poll.saved'); - var index = $scope.data.choices.indexOf(choice); - if (index > -1) { - $scope.data.choices.splice(index,1); - } - }, function (error) { - if (error.status == 400) { - angular.extend($scope.restError, error.data); - if (angular.isDefined(error.data.choice)) { - $rootScope.$broadcast('newError', error.data.choice[0]); - } - } - else { - var index = $scope.data.choices.indexOf(choice); - if (index > -1) { - $scope.data.choices.splice(index,1); - } - } - }); - }; - - $scope.saveChoice = function (choice) { - if (angular.isDefined(choice)) { - if (angular.isDefined(choice.id) && choice.id != null) { - $scope.callBackEditChoice(choice); - } - else { - $scope.callBackAddChoice(choice); - } - } - } - - //////////////////////////////// //// VOTER LIST ///// //////////////////////////////// @@ -1027,8 +1046,14 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }]) +////////////////////////////////// +// Vote controller // +////////////////////////////////// + .controller('PollVoteCtrl', ['$scope', '$rootScope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', '$translate', '$location', 'Page', function ($scope, $rootScope, $q, $controller, $routeParams, Poll, PollChoice, PollVote, $translate, $location, Page) { + $controller('PollAdminChoiceCtrl', {$scope:$scope}); + if (angular.isUndefined($scope.globalVariables)) { $scope.globalVariables = {}; } @@ -1204,6 +1229,10 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }]) +////////////////////////////////// +// Comment controller // +////////////////////////////////// + .controller('PollCommentCtrl', ['$scope', '$rootScope', '$controller', '$routeParams', 'Poll', 'PollComment', '$translate', '$timeout', '$location', 'Page', function ( $scope, $rootScope, $controller, $routeParams, Poll, PollComment, $translate, $timeout, $location, Page) { @@ -1370,6 +1399,10 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }]) +////////////////////////////////// +// Result of poll controller // +////////////////////////////////// + .controller('PollResultCtrl', ['$scope', '$q', '$controller', '$route', '$routeParams', 'Poll', 'PollChoice', 'PollVote', '$translate', '$filter', '$timeout', 'Page', function ($scope, $q, $controller, $route, $routeParams, Poll, PollChoice, PollVote, $translate, $filter, $timeout, Page) { if (angular.isUndefined($scope.globalVariables)) { @@ -1456,6 +1489,10 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }]) +////////////////////////////////// +// List of poll controller // +////////////////////////////////// + .controller('PollListCtrl', ['$scope', '$rootScope', '$controller', '$routeParams', '$timeout', '$location', '$sce', '$q', 'Poll', 'Page', function ($scope, $rootScope, $controller, $routeParams, $timeout, $location, $sce, $q, Poll, Page) { diff --git a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html index 82bca7b..730e339 100644 --- a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html @@ -27,22 +27,22 @@ </td> <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}}"> + <div ng-hide="showEdit && ((data.poll.addChoiceAllowed && choice.permission) || globalVariables.editMode)" class="fixe-input" title="{{choice.description}}"> {{ choice.choiceValue || ('poll.edit' | translate) }} <info-error error="choice.restError.choiceValue[0]" data="choice.choiceValue"></info-error> - <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"> + <input type="button" class="btn btn-default" ng-if="(data.poll.choiceAddAllowed && choice.permission) || globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> + <div ng-show="showEdit && ((data.poll.addChoiceAllowed && choice.permission) || globalVariables.editMode)"> <input type="text" class="form-control" ng-model="choice.choiceValue" focus-me="showEdit" ng-exit="showEdit = false;" auto-save="saveChoice(choice)" required/> <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> </div> </div> <div ng-if="choice.choiceType == 'DATE'" edit-me="showEdit" > - <div ng-hide="!globalVariables.voted && showEdit || isOpen" class="fixe-input" title="{{choice.description}}"> + <div ng-hide="showEdit && (data.poll.addChoiceAllowed && choice.permission || globalVariables.editMode)" class="fixe-input" title="{{choice.description}}"> {{ (choice.choiceValue | date:globalVariables.dateTimeFormat) || ('poll.edit' | translate) }} <info-error error="choice.restError.choiceValue[0]" data="choice.choiceValue"></info-error> - <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/> + <input type="button" class="btn btn-default" ng-if="(data.poll.choiceAddAllowed && choice.permission) || globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/> </div> - <div ng-show="!globalVariables.voted && showEdit" > + <div ng-show="showEdit && (data.poll.choiceAddAllowed && choice.permission || globalVariables.editMode)" > <datetimepicker ng-model="choice.choiceValue" focus="showEdit" ng-exit="showEdit = false" ng-save="saveChoice(choice)"></datetimepicker> <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> </div> @@ -51,7 +51,7 @@ <div class="fixe-input" title="{{choice.description}}"> {{choice.choiceValue.meta.name}} <info-error error="choice.restError.choiceValue[0]" data="choice.choiceValue"></info-error> - <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/> + <input type="button" class="btn btn-default" ng-if="data.poll.choiceAddAllowed && choice.permission || globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/> <br/> <print-resource image="choice.choiceValue.id" name="choice.choiceValue.meta.name"></print-resource> @@ -60,7 +60,7 @@ </div> </td> - <td ng-if="!globalVariables.voted && globalVariables.editMode"><button class="btn btn-default btn-large" ng-click="addChoice()"> <span class="glyphicon glyphicon-plus"></span> </button></td> + <td ng-if="data.poll.choiceAddAllowed || globalVariables.editMode"><button class="btn btn-default btn-large" ng-click="addChoice()"> <span class="glyphicon glyphicon-plus"></span> </button></td> </tr> <!-- end print choice --> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.