Author: garandel Date: 2014-04-28 17:39:15 +0200 (Mon, 28 Apr 2014) New Revision: 3883 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3883 Log: d?\195?\169sactivation de certain modification apres le 1er vote Modified: trunk/pollen-ui-angular/src/main/webapp/css/style.css 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/poll-popupChoice.html trunk/pollen-ui-angular/src/main/webapp/partials/poll.html Modified: trunk/pollen-ui-angular/src/main/webapp/css/style.css =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/css/style.css 2014-04-28 09:56:29 UTC (rev 3882) +++ trunk/pollen-ui-angular/src/main/webapp/css/style.css 2014-04-28 15:39:15 UTC (rev 3883) @@ -133,12 +133,14 @@ margin:auto; margin-bottom:8px; } -#poll tr, #poll tr td { - border-collapse: collapse; + +#poll tr td > .btn-large { + height:60px; + width:80px; } + .pollChoice { - height:60px; min-width:150px; padding-left:5px; padding-right:5px; @@ -146,10 +148,9 @@ padding-bottom:5px; border: 1px dashed #AAAAAA; text-align:center; - padding-left:5px; - padding-right:5px; -} -.pollChoice input[type=text]{ + } +. +pollChoice input[type=text]{ height:25px; width:140px; } Modified: trunk/pollen-ui-angular/src/main/webapp/index.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/index.html 2014-04-28 09:56:29 UTC (rev 3882) +++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-04-28 15:39:15 UTC (rev 3883) @@ -32,7 +32,6 @@ <script src="js/app.js"></script> <script src="js/controllers/pollCtrl.js"></script> - <script src="js/services.js"></script> </head> <body> Modified: trunk/pollen-ui-angular/src/main/webapp/js/app.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-04-28 09:56:29 UTC (rev 3882) +++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-04-28 15:39:15 UTC (rev 3883) @@ -18,19 +18,18 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollen', ["ngRoute", "pollenControllers", "pollenServices", 'ui.bootstrap']) +angular.module('pollen', ["ngRoute", "pollControllers", 'ui.bootstrap']) .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', {templateUrl: 'partials/home.html', controller: "HomeCtrl"}) - .when('/poll/create', {templateUrl: 'partials/poll.html', controller: "PollCreateCtrl"}) + .when('/poll/create', {templateUrl: 'partials/poll.html', controller: "PollAdminCtrl"}) + .when('/poll/edit/:pollId', {templateUrl: 'partials/poll.html', controller:"PollAdminCtrl"}) .when('/poll/vote', {templateUrl: 'partials/poll.html', controller :"PollVoteCtrl"}) + .when('/poll/list', {templateUrl: 'partials/poll-list.html', controller :"PollListCtrl"}) .otherwise({redirectTo: '/'}); -}]).config(['$httpProvider', function($httpProvider) { - - $httpProvider.defaults.useXDomain = true; - delete $httpProvider.defaults.headers.common['X-Requested-With']; }]) + .directive('focusMe', function($timeout) { return { link: function($scope, element, attrs) { @@ -51,10 +50,10 @@ restrict:'A', link: function ($scope, element, attrs) { element.bind('click', function () { - if ($scope.gvar.editMode) { + if ($scope.globalVariables.editMode) { $scope.$apply(function () { $scope[attrs.editMe] = true; - $scope.gvar.saved = false; + $scope.globalVariables.saved = false; }); } }); Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-04-28 09:56:29 UTC (rev 3882) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-04-28 15:39:15 UTC (rev 3883) @@ -18,15 +18,15 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollenControllers', []).controller('HomeCtrl', ['$scope', '$http', function ($scope, $http) { +angular.module('pollControllers', []).controller('HomeCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) { }]) .controller('PollCtrl', ['$scope', '$sce', '$timeout', 'pollStorage', function ($scope, $sce, $timeout, pollStorage) { - $scope.gvar = {saved:false}; - $scope.$watch('gvar.saved', function() { + $scope.globalVariables = {saved:false}; + $scope.$watch('globalVariables.saved', function() { $timeout(function () { - $scope.gvar.saved = false; + $scope.globalVariables.saved = false; }, 5000); }); @@ -35,130 +35,161 @@ $scope.toHTML = function (data) { return $sce.trustAsHtml(data); } - }]) -.controller('PollCreateCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'pollStorage', function ($scope, $controller, $modal, $filter, $timeout, pollStorage) { + +.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'pollStorage', function ($scope, $controller, $modal, $filter, $timeout, pollStorage) { $controller('PollCtrl', {$scope:$scope}); - function initPoll() { - return { - title :'', - description : '', - choices : [] - }; - } + var initPoll = function () { + return { + title :'', + description : '', + choices : [] + }; + } - function initChoice() { - return { - name: '', - type: 'text' - }; - } + var initChoice = function () { + return { + name: '', + type: $scope.globalVariables.lastType + }; + } - $scope.gvar.editMode = true; + $scope.globalVariables.editMode = true; + $scope.globalVariables.voted = angular.isDefined($scope.poll.votants); + $scope.globalVariables.lastType = 'text'; - if (JSON.stringify($scope.poll) == "{}") { - $scope.poll = initPoll(); - } + $scope.$watch('pollForm.$valid', function (newVal) { + $scope.formValid = newVal; + $scope.globalVariables.errorForm = false; + }); - $scope.voteChoices = $scope.poll.choices; + if (!angular.isDefined($scope.poll.choices)) { + $scope.poll = initPoll(); + } + $scope.voteChoices = $scope.poll.choices; - $scope.addChoice = function () { - var index = $scope.poll.choices.push(initChoice()); - var choice = $scope.poll.choices[index-1]; - popupChoice(choice, 'Add Choice'); + $scope.addChoice = function () { + var index = $scope.poll.choices.push(initChoice()); + var choice = $scope.poll.choices[index-1]; + popupChoice(choice, 'Add Choice'); + } - } + $scope.editChoice = function (choice) { + popupChoice(choice, 'Edit Choice'); + } - $scope.editChoice = function (choice) { - popupChoice(choice, 'Edit Choice'); + var deleteChoice = function (ch) { + var index = $scope.poll.choices.indexOf(ch); + if (index > -1) { + $scope.poll.choices.splice(index,1); } + } - var deleteChoice = function (ch) { - var index = $scope.poll.choices.indexOf(ch); - if (index > -1) { - $scope.poll.choices.splice(index,1); - } - } - var popupChoice = function (choice, title) { - var modalInstance = $modal.open({ - templateUrl : 'partials/poll-popupChoice.html', - controller : PollPopChoiceCtrl, - resolve : { - title : function () { return title;}, - choice : function () { return choice; } - } - }); + var popupChoice = function (choice, title) { + var modalInstance = $modal.open({ + templateUrl : 'partials/poll-popupChoice.html', + controller : PollPopChoiceCtrl, + resolve : { + title : function () { return title;}, + choice : function () { return choice; } + } + }); - modalInstance.result.then(function (ch) { - deleteChoice(ch); - }); - } + modalInstance.result.then(function (ch) { + deleteChoice(ch); + }, function () { + $scope.globalVariables.lastType = choice.type; + }); + } - $scope.save = function () { - pollStorage.put($scope.poll); - $scope.gvar.saved = true; + $scope.save = function () { + if ($scope.formValid) { + pollStorage.put($scope.poll); + $scope.globalVariables.saved = true; } - - $scope.reset = function () { - $scope.poll = initPoll(); - $scope.voteChoices = $scope.poll.choices; - pollStorage.put({}); + else { + $scope.globalVariables.errorForm = true; } - var PollPopChoiceCtrl = function ($scope, $filter, $modalInstance, title, choice) { - $scope.title = title; - $scope.choice = choice; - var oldChoice = angular.copy(choice); + } - $scope.saveChoice = function () { - $modalInstance.close(); - } + $scope.reset = function () { + $scope.poll = initPoll(); + $scope.voteChoices = $scope.poll.choices; + pollStorage.put({}); + } - $scope.cancelChoice = function () { - angular.copy(oldChoice, $scope.choice); - $modalInstance.close(); - } + $scope.delete = function () { + $scope.poll = initPoll(); + $scope.voteChoices = $scope.poll.choices; + pollStorage.put({}); + } - $scope.deleteChoice = function (ch) { - $modalInstance.close(ch); - } + var PollPopChoiceCtrl = function ($scope, $filter, $modalInstance, title, choice) { + $scope.title = title; + $scope.choice = choice; + var oldChoice = angular.copy(choice); + + $scope.saveChoice = function () { + $modalInstance.dismiss(); } + + $scope.cancelChoice = function () { + angular.copy(oldChoice, $scope.choice); + $modalInstance.dismiss(); + } + + $scope.deleteChoice = function (ch) { + $modalInstance.close(ch); + } + + } }]) .controller('PollVoteCtrl', ['$scope', '$filter', '$controller', 'pollStorage', function ($scope, $filter, $controller, pollStorage) { $controller('PollCtrl', {$scope:$scope}); - $scope.gvar.editMode = false; + $scope.globalVariables.editMode = false; - var initVote = function () { - $scope.voteName = ""; - $scope.voteChoices = []; - for (var i = 0; i < $scope.poll.choices.length; ++i) { - if ($scope.poll.choices[i].type == 'text') { - $scope.voteChoices.push({name:$scope.poll.choices[i].name, value:false}); - } - else if ($scope.poll.choices[i].type == 'date') { - $scope.voteChoices.push({name: $filter('date')($scope.poll.choices[i].date,'dd/MM/yyyy') , value:false}); - } + var initVote = function () { + $scope.voteName = ""; + $scope.voteChoices = []; + for (var i = 0; i < $scope.poll.choices.length; ++i) { + if ($scope.poll.choices[i].type == 'text') { + $scope.voteChoices.push({name:$scope.poll.choices[i].name, value:false}); } + else if ($scope.poll.choices[i].type == 'date') { + $scope.voteChoices.push({name: $scope.poll.choices[i].date , value:false}); + } } - initVote(); + } + initVote(); - $scope.vote = function () { - var data = {}; - data.name = $scope.voteName; - data.choices = angular.copy($scope.voteChoices); - if (!angular.isDefined($scope.poll.votants)) { - $scope.poll.votants = []; - } - $scope.poll.votants.push(data); - pollStorage.put($scope.poll); - $scope.gvar.saved = true; - initVote(); + $scope.vote = function () { + if ($scope.voteName != '') { + var data = {}; + data.name = $scope.voteName; + data.choices = angular.copy($scope.voteChoices); + if (!angular.isDefined($scope.poll.votants)) { + $scope.poll.votants = []; + } + $scope.poll.votants.push(data); + pollStorage.put($scope.poll); + $scope.globalVariables.saved = true; + initVote(); } + else { + $scope.globalVariables.errorForm = true; + } + } }]) + +.controller('PollListCtrl', ['$scope', 'pollStorage', function ($scope, pollStorage) { + +}]) + ; \ No newline at end of file Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html 2014-04-28 09:56:29 UTC (rev 3882) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html 2014-04-28 15:39:15 UTC (rev 3883) @@ -1,7 +1,6 @@ <form class="form-horizontal"> <div class="modal-header"> <h4 class="modal-title">{{title}}</h4> - {{oldChoice}} </div> <div class="modal-body"> Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-04-28 09:56:29 UTC (rev 3882) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-04-28 15:39:15 UTC (rev 3883) @@ -20,14 +20,18 @@ ~ #L% ~ --> -<form class="form-inline"> - <alert type="'success'" ng-if="gvar.editMode && gvar.saved"> Sondage sauvegardé..</alert> - <alert type="'success'" ng-if="!gvar.editMode && gvar.saved"> Vote effectué.. </alert> +<form class="form-inline" name="pollForm" novalidate> + <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é.. </alert> + + <alert type="'warning'" ng-if="globalVariables.voted"> Les votes ont commencé, certaine modification sont inaccessible.. </alert> + <div class="pollTitle pollAnim" edit-me="showEditTitle"> <h1 ng-hide="showEditTitle"> {{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"/></h1> + <h1 ng-show="showEditTitle"><input type="text" class="form-control" focus-me="showEditTitle" ng-model="poll.title" ng-exit="showEditTitle = false" required/></h1> </div> <div ng-hide="showEditDesc" class="pollDesc pollAnim" edit-me="showEditDesc"> @@ -44,23 +48,23 @@ <table> <tr> <td class="pollChoice"></td> - <td ng-repeat="choice in poll.choices" class="pollChoice pollAnim" edit-me="showEdit" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> - <div ng-show="choice.type == 'text'"> - <div ng-hide="showEdit" class="fixe-input" title="{{choice.description}}">{{choice.name}} <input type="button" class="btn btn-default" ng-if="gvar.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> - <div ng-show="showEdit"> - <input type="text" class="form-control" ng-model="choice.name" focus-me="showEdit" ng-exit="showEdit = false"/> + <td ng-repeat="choice in poll.choices" class="pollChoice pollAnim" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> + <div ng-if="choice.type == '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"> + <input type="text" class="form-control" ng-model="choice.name" focus-me="showEdit" ng-exit="showEdit = false" required/> <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> </div> </div> - <div ng-show="choice.type == 'date'"> - <div ng-hide="showEdit || isOpen" class="fixe-input" title="{{choice.description}}">{{choice.date | date:'dd/MM/yyyy'}} <input type="button" class="btn btn-default" ng-if="gvar.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> - <div ng-show="showEdit || isOpen" > - <input type="text" class="form-control" ng-model="choice.date" focus-me="showEdit" datepicker-popup="dd/MM/yyyy" is-open="isOpen" ng-exit="showEdit = false" /> + <div ng-if="choice.type == 'date'" edit-me="showEdit" > + <div ng-hide="!globalVariables.voted && showEdit || isOpen" class="fixe-input" title="{{choice.description}}">{{choice.date | date:'dd/MM/yyyy'}} <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="!globalVariables.voted && showEdit || isOpen" > + <input type="text" class="form-control" ng-model="choice.date" focus-me="showEdit" datepicker-popup="dd/MM/yyyy" is-open="isOpen" ng-exit="showEdit = false" required/> <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> </div> </div> </td> - <td ng-if="gvar.editMode"><input type="button" class="btn btn-default" value="+" ng-click="addChoice()"/></td> + <td ng-if="!globalVariables.voted && globalVariables.editMode"><input type="button" class="btn btn-default btn-large" value="+" ng-click="addChoice()"/></td> </tr> <tr> @@ -68,7 +72,9 @@ <td ng-repeat="choice in voteChoices" class="pollChoice"> <input type="checkbox" name="{{choice.name}}" ng-model="choice.value"/> </td> - <td></td> + <td> + <input class="btn btn-primary btn-large" type="button" value="Vote" ng-click="vote()" /> + </td> </tr> <tr ng-repeat="vote in poll.votants track by $index" class="pollAnim"> @@ -79,15 +85,13 @@ </tr> </table> - <div ng-if="gvar.editMode"> - <input class="btn btn-primary" type="button" value="Save" ng-click="save()"/> - <br/><br/><br/> - <input type="button" value="reset" ng-click="reset();"/> + <div ng-if="globalVariables.editMode"> + <button class="btn btn-primary" ng-click="save()">Save</button> + <button class="btn btn-warning" ng-click="reset();" ng-if="!globalVariables.voted">Reset</button> + <button class="btn btn-danger" ng-click="delete();">Delete</button> </div> - <div ng-if="!gvar.editMode"> - <input class="btn btn-primary" type="button" value="Vote" ng-click="vote()" /> - </div> + </div> </form>