01/02: change countingType, change route
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 c93c8b0887617ebdcd7e0970a9cbc9bdb424d7e0 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jun 25 17:19:03 2014 +0200 change countingType, change route --- pollen-ui-angular/src/main/webapp/js/app.js | 14 +-- .../src/main/webapp/js/controllers/pollCtrl.js | 115 +++++++++++++++------ pollen-ui-angular/src/main/webapp/js/directives.js | 4 +- .../src/main/webapp/partials/poll-poll.html | 2 +- .../src/main/webapp/partials/poll-popupChoice.html | 2 +- .../src/main/webapp/partials/poll-result.html | 2 +- .../src/main/webapp/partials/poll.html | 6 +- 7 files changed, 100 insertions(+), 45 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index 133ef9c..00bbfe7 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -57,13 +57,13 @@ angular.module('pollen', ['pollenDirective', 'pollenServices', 'ngRoute', 'pollC .config(['$routeProvider', function($routeProvider) { $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/:pollId', {templateUrl: './partials/poll.html', controller :"PollVoteCtrl"}) - .when('/poll/result/:pollId', {templateUrl: './partials/poll.html', controller :"PollResultCtrl"}) - .when('/poll/comment/:pollId', {templateUrl: './partials/poll.html', controller :"PollCommentCtrl"}) - .when('/poll/list', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) - .when('/poll/list/:cmd', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) + .when('/poll/home/:pollId', {templateUrl: './partials/poll.html', controller: "PollCtrl"}) + .when('/poll/create/:tab?', {templateUrl: './partials/poll.html', controller: "PollCreateCtrl"}) + .when('/poll/edit/:pollId/:token?/:tab?', {templateUrl: './partials/poll.html', controller:"PollEditCtrl"}) + .when('/poll/vote/:pollId/:token?', {templateUrl: './partials/poll.html', controller :"PollVoteCtrl"}) + .when('/poll/result/:pollId/:token?', {templateUrl: './partials/poll.html', controller :"PollResultCtrl"}) + .when('/poll/comment/:pollId/:token?', {templateUrl: './partials/poll.html', controller :"PollCommentCtrl"}) + .when('/poll/list/:cmd?', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) .when('/user/register', {templateUrl: './partials/user-register.html', controller:"UserRegisterCtrl"}) .when('/user/edit', {templateUrl: './partials/user-edit.html', controller:"UserEditCtrl"}) .when('/user/lostpassword', {templateUrl: './partials/user-lostPassword.html', controller:"UserLostPasswordCtrl"}) 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 6ff94fd..a3e0eda 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -35,6 +35,8 @@ angular.module('pollControllers', []) } }; + $scope.tab = $scope.setTab('home'); + $scope.setUrl = function (exclude) { var url = window.location.origin+window.location.pathname+'#'+$location.path(); if ($location.search().length != 0) { @@ -50,9 +52,6 @@ angular.module('pollControllers', []) return url; }; - $scope.urlTab = $scope.setUrl(['tab']); - - if (angular.isUndefined($scope.globalVariables)) { $scope.globalVariables = {}; @@ -108,24 +107,26 @@ angular.module('pollControllers', []) pollDeferred.promise.then(function () { var baseUrl = window.location.origin+window.location.pathname; + $scope.globalVariables.linkHome = baseUrl; $scope.globalVariables.linkVote = baseUrl; $scope.globalVariables.linkComment = baseUrl; $scope.globalVariables.linkEdit = baseUrl; $scope.globalVariables.linkResult = baseUrl; + $scope.globalVariables.linkHome += '#/poll/home/'+$routeParams.pollId; $scope.globalVariables.linkVote += '#/poll/vote/'+$routeParams.pollId; $scope.globalVariables.linkComment += '#/poll/comment/'+$routeParams.pollId; $scope.globalVariables.linkEdit += '#/poll/edit/'+$routeParams.pollId; $scope.globalVariables.linkResult += '#/poll/result/'+$routeParams.pollId; if (angular.isDefined($scope.globalVariables.permission)) { - $scope.globalVariables.linkEdit += '?token='+$scope.globalVariables.permission; - $scope.globalVariables.linkResult += '?token='+$scope.globalVariables.permission; - $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'&tab=conf'; - $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'&tab=participant'; + $scope.globalVariables.linkEdit += '/'+$scope.globalVariables.permission; + $scope.globalVariables.linkResult += '/'+$scope.globalVariables.permission; + $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'/conf'; + $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'/participant'; } else { - $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'?tab=conf'; - $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'?tab=participant'; + $scope.globalVariables.linkConf = $scope.globalVariables.linkEdit+'/conf'; + $scope.globalVariables.linkParticipant = $scope.globalVariables.linkEdit+'/participant'; } }); } @@ -165,6 +166,50 @@ angular.module('pollControllers', []) } }); + $scope.getInputType = function () { + if ($scope.voteCountingIsBoolean()) { + return 'checkbox'; + } else { + return 'text'; + } + } + + $scope.getChoiceValue = function (choiceValue) { + if ($scope.voteCountingIsBoolean()) { + return (choiceValue)?true:false; + } + else { + if (choiceValue === true) { + return 1.0; + } + else if (choiceValue === false) { + return 0.0; + } + else { + choiceValue; + } + } + } + + $scope.$watch('data.poll.voteCountingType', function (newVal, oldVal) { + if ((newVal == 1 || oldVal == 1) && newVal != oldVal) { + console.log('vote Change'); + angular.forEach($scope.data.votants, function(votant, key) { + angular.forEach(votant.choice, function (choice) { + choice.inputType = $scope.getInputType(); + choice.voteValue = $scope.getChoiceValue(choice.voteValue); + }) + }); + } + }) + + $scope.voteCountingIsBoolean = function () { + if (angular.isDefined($scope.data.poll) && angular.isDefined($scope.data.poll.voteCountingType)) { + return $scope.data.poll.voteCountingType == 1; + } + return false; + } + }]) .controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$timeout', '$routeParams', function ($scope, $controller, $modal, $timeout, $routeParams) { @@ -236,7 +281,7 @@ angular.module('pollControllers', []) name: '', date: $scope.globalVariables.lastDate, choiceType: $scope.globalVariables.lastType, - inputType:'checkbox' + inputType: $scope.getInputType() }; } @@ -668,13 +713,15 @@ angular.module('pollControllers', []) $scope.data.votants = votes; angular.forEach($scope.data.votants, function (vote) { angular.forEach(vote.choice, function (choice) { - if (choice.voteValue != null && choice.voteValue != 0.0) { - choice.voteValue = true; - } - else { - choice.voteValue = false; + if ($scope.voteCountingIsBoolean()) { + if (choice.voteValue != null && choice.voteValue != 0.0) { + choice.voteValue = true; + } + else { + choice.voteValue = false; + } } - choice.inputType = 'checkbox'; + choice.inputType = $scope.getInputType(); }) }) }); @@ -690,10 +737,12 @@ angular.module('pollControllers', []) $location.path('/'); }); - - + var oldPoll = angular.copy($scope.data.poll); $scope.autoSavePoll = function () { - $scope.savePoll(); + if (!angular.equals(oldPoll, $scope.data.poll)) { + $scope.savePoll(); + oldPoll = angular.copy($scope.data.poll); + } }; $scope.savePoll = function () { @@ -744,13 +793,15 @@ angular.module('pollControllers', []) $scope.data.votants = votes; angular.forEach($scope.data.votants, function (vote) { angular.forEach(vote.choice, function (choice) { - if (choice.voteValue != null && choice.voteValue != 0.0) { - choice.voteValue = true; - } - else { - choice.voteValue = false; + if ($scope.voteCountingIsBoolean()) { + if (choice.voteValue != null && choice.voteValue != 0.0) { + choice.voteValue = true; + } + else { + choice.voteValue = false; + } } - choice.inputType = 'checkbox'; + choice.inputType = $scope.getInputType(); }) }) }); @@ -777,16 +828,22 @@ angular.module('pollControllers', []) initAuthor(); $scope.data.vote.anonymous = false; $scope.data.vote.choice = []; + + var defaultValue = ($scope.voteCountingIsBoolean()) ? false : 0.0; + for (var i = 0; i < $scope.data.choices.length; ++i) { - $scope.data.vote.choice.push({choiceId:$scope.data.choices[i].id, voteValue:false, inputType:'checkbox'}); + + $scope.data.vote.choice.push({'choiceId':$scope.data.choices[i].id, 'voteValue': defaultValue, 'inputType': $scope.getInputType()}); } } $scope.voter = function () { var sendVote = angular.copy($scope.data.vote); - angular.forEach(sendVote.choice, function (choice) { - choice.voteValue = (choice.voteValue) ? 1.0 : 0.0; - }); + if ($scope.voteCountingIsBoolean()) { + angular.forEach(sendVote.choice, function (choice) { + choice.voteValue = (choice.voteValue) ? 1.0 : 0.0; + }); + } if (angular.isDefined($scope.data.vote.id)) { // edit vote diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index 4abdc16..051cb75 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -293,8 +293,7 @@ angular.module('pollenDirective', []) return { restrict : 'E', scope : { - data:'=', - max:'=' + data:'=' }, template:'<div class="jqplot-target"></div>', link: function(scope, element, attrs) { @@ -314,7 +313,6 @@ angular.module('pollenDirective', []) axesDefaults: { showTicks: true, showTickMarks: true, - max: scope.max, tickOptions: { showGridline: false, show:true, diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-poll.html b/pollen-ui-angular/src/main/webapp/partials/poll-poll.html index ede3062..a4497f9 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-poll.html @@ -38,7 +38,7 @@ <!-- fix me : no save in creation but save in edition --> <button type="button" class="btn btn-primary" ng-click="showEditDesc = false;" ng-show="globalVariables.create">{{ 'action.return' | translate }}</button> - <button type="button" class="btn btn-primary" ng-click="showEditDesc = false; savePoll()" ng-show="globalVariables.edit">{{ 'action.return' | translate }}</button> + <button type="button" class="btn btn-primary" ng-click="showEditDesc = false; autoSavePoll()" ng-show="globalVariables.edit">{{ 'action.return' | translate }}</button> </div> <div id="poll"> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html index 402cf6a..f86dfca 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html @@ -31,7 +31,7 @@ <div class="col-sm-8 btn-group"> <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'TEXT'">Text</button> <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'DATE'" disabled>Date</button> - <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'PICTURE'" disabled>Image</button> + <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'IMAGE'" disabled>Image</button> </div> </div> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-result.html b/pollen-ui-angular/src/main/webapp/partials/poll-result.html index 47af606..5277130 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-result.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-result.html @@ -11,7 +11,7 @@ </div> <div class="plot"> <div ng-if="plot == 'chart'"> - <chart data="data.result.scoresChart" max="data.result.nbVotant"></chart> + <chart data="data.result.scoresChart"></chart> </div> <div ng-if="plot == 'pie'"> <pie data="data.result.scoresChart"></pie> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html index 58bc694..b974c20 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll.html @@ -21,14 +21,14 @@ <div> <ul class="nav nav-tabs"> - <li ng-class="{active: tab == 'home'}"><a href="{{urlTab}}tab=home" ng-click="tab = 'home'"> <span class="glyphicon glyphicon-home"></span> </a></li> + <li ng-class="{active: tab == 'home'}"><a href="{{globalVariables.linkHome || '#/poll/create/home' }}" ng-click="tab = 'home'"> <span class="glyphicon glyphicon-home"></span> </a></li> <li ng-class="{active: tab == 'vote'}" ng-show="data.poll.id"><a href="{{globalVariables.linkVote}}" ng-click="tab = 'vote'">{{ 'poll.tab.vote' | translate }}</a></li> <li ng-class="{active: tab == 'comment'}" ng-show="data.poll.id"><a href="{{globalVariables.linkComment}}" ng-click="tab = 'comment'">{{ 'poll.tab.comment' | translate }}</a></li> <li ng-class="{active: tab == 'result'}" ng-show="!globalVariables.create"><a href="{{globalVariables.linkResult}}" ng-click="tab = 'result'">{{ 'poll.tab.result' | translate }}</a></li> <li ng-class="{active: tab == 'edit'}" ng-show="globalVariables.create"><a href="#/poll/create" ng-click="tab = 'edit'">{{ 'poll.tab.create' | translate }}</a></li> <li ng-class="{active: tab == 'edit'}" ng-show="data.poll.permission"><a href="{{globalVariables.linkEdit}}" ng-click="tab = 'edit'">{{ 'poll.tab.edit' | translate }}</a></li> - <li ng-class="{active: tab == 'conf'}" ng-show="data.poll.permission || globalVariables.create"><a href="{{globalVariables.linkConf || '#/poll/create?tab=conf'}}" ng-click="tab = 'conf'">{{ 'poll.tab.conf' | translate }}</a></li> - <li ng-class="{active: tab == 'participant'}" ng-show="data.poll.permission || globalVariables.create"><a href="{{globalVariables.linkParticipant || '#/poll/create?tab=participant'}}" ng-click="tab = 'participant'">{{ 'poll.tab.participant' | translate }}</a></li> + <li ng-class="{active: tab == 'conf'}" ng-show="data.poll.permission || globalVariables.create"><a href="{{globalVariables.linkConf || '#/poll/create/conf'}}" ng-click="tab = 'conf'">{{ 'poll.tab.conf' | translate }}</a></li> + <li ng-class="{active: tab == 'participant'}" ng-show="data.poll.permission || globalVariables.create"><a href="{{globalVariables.linkParticipant || '#/poll/create/participant'}}" ng-click="tab = 'participant'">{{ 'poll.tab.participant' | translate }}</a></li> </ul> <div ng-include="'./partials/poll-link.html'" ng-if="tab == 'home'"></div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm