02/04: update tab and save permission on offline
This is an automated email from the git hooks/post-receive script. New commit to branch devel in repository Pollen. See http://git.None/Pollen.git commit 214d089987eb80136a30d776e5eecb48333c9aff Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Mon May 26 14:37:21 2014 +0200 update tab and save permission on offline --- .../src/main/webapp/js/controllers/pollCtrl.js | 65 ++++++++++++++++------ .../src/main/webapp/partials/poll.html | 12 ++-- 2 files changed, 55 insertions(+), 22 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 202b551..f19bd8e 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -23,12 +23,6 @@ angular.module('pollControllers', []) }]) .controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', function ($scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage) { - if (angular.isDefined($routeParams.tab)) { - $scope.tab = $routeParams.tab; - } - else { - $scope.tab = 'poll'; - } $scope.url = $location.protocol()+'://'+$location.host()+'/#'+$location.path(); if ($location.search().length != 0) { @@ -51,7 +45,30 @@ angular.module('pollControllers', []) $scope.globalVariables.saved = false; }, 5000); }); + + /** + * Sauvegarde du token si non connecté + */ + var session = SessionStorage.get(); + if (angular.isUndefined($routeParams.token) && angular.isUndefined(session.id)) { // pas de paramètre url et non connecté + if (angular.isDefined(session.permission) && session.permission != '') { // existe une permission + $scope.globalVariables.permission = session.permission; + } + else if (session.permission == '') { + SessionStorage.remove('permission'); + } + } + else if (angular.isDefined(session.id)) { // connecté + if (angular.isDefined(session.permission)) { // connecté => pas besoin de permission + SessionStorage.remove('permission'); + } + } + else { //token dans l'URL + SessionStorage.save({permission:$routeParams.token}); + $scope.globalVariables.permission = $routeParams.token; + } } + $scope.data = {}; $scope.data.poll = {}; @@ -59,8 +76,8 @@ angular.module('pollControllers', []) $scope.globalVariables.linkVote = $location.protocol()+'://'+$location.host()+'/#/poll/vote/'+$routeParams.pollId; $scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId; - if (angular.isDefined($routeParams.token)) { - $scope.globalVariables.linkEdit += '?token='+$routeParams.token; + if (angular.isDefined($scope.globalVariables.permission)) { + $scope.globalVariables.linkEdit += '?token='+$scope.globalVariables.permission; } } @@ -96,9 +113,16 @@ angular.module('pollControllers', []) }]) -.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', function ($scope, $controller, $modal, $filter, $timeout) { +.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', '$routeParams', function ($scope, $controller, $modal, $filter, $timeout, $routeParams) { $controller('PollCtrl', {$scope:$scope}); + if (angular.isDefined($routeParams.tab)) { + $scope.tab = $routeParams.tab; + } + else { + $scope.tab = 'edit'; + } + var initChoice = function () { return { name: '', @@ -237,7 +261,7 @@ angular.module('pollControllers', []) $scope.globalVariables.edit = true; $scope.callBackAddChoice = function (choice) { - PollChoice.add({pollId:$routeParams.pollId, permission:$routeParams.token}, choice, function (data) { + PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, choice, function (data) { delete choice.restError; choice.topiaId = data.topiaId; $scope.globalVariables.saved = true; @@ -247,7 +271,7 @@ angular.module('pollControllers', []) } $scope.callBackEditChoice = function (choice) { - PollChoice.update({pollId:$routeParams.pollId, permission:$routeParams.token}, choice, function() { + PollChoice.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, choice, function() { delete choice.restError; $scope.globalVariables.saved = true; }, function (error) { @@ -256,7 +280,7 @@ angular.module('pollControllers', []) } $scope.deleteChoice = function (choice) { - PollChoice.remove({pollId:$routeParams.pollId, permission:$routeParams.token, choiceId: choice.id}, function () { + PollChoice.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission, choiceId: choice.id}, function () { $scope.globalVariables.saved = true; var index = $scope.data.choices.indexOf(choice); if (index > -1) { @@ -268,14 +292,14 @@ angular.module('pollControllers', []) } var initPoll = function () { - var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$routeParams.token}, function (poll) { + var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { if (angular.isUndefined(poll.permission)) { $location.path('/'); } $scope.data.poll = poll; }).$promise; - var choicesPromise = PollChoice.query({pollId:$routeParams.pollId, permission:$routeParams.token}).$promise.then(function (choices) { + var choicesPromise = PollChoice.query({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}).$promise.then(function (choices) { $scope.data.choices = choices; $scope.data.vote = {}; $scope.data.vote.choice = $scope.data.choices; @@ -314,7 +338,7 @@ angular.module('pollControllers', []) initPoll(); $scope.savePoll = function () { - $scope.data.poll.$update({permission:$routeParams.token}, function (data) { + $scope.data.poll.$update({permission:$scope.globalVariables.permission}, function (data) { $scope.globalVariables.saved = true; }, function (error) { angular.extend($scope.restError, error.data); @@ -333,7 +357,7 @@ angular.module('pollControllers', []) } $scope.deletePoll = function () { - $scope.data.poll.$remove({permission:$routeParams.token}, function() { + $scope.data.poll.$remove({permission:$scope.globalVariables.permission}, function() { $location.path('/'); }); } @@ -342,10 +366,17 @@ angular.module('pollControllers', []) .controller('PollVoteCtrl', ['$scope', '$q', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $filter, $controller, $routeParams, Poll, PollChoice, PollVote) { $controller('PollCtrl', {$scope:$scope}); + if (angular.isDefined($routeParams.tab)) { + $scope.tab = $routeParams.tab; + } + else { + $scope.tab = 'vote'; + } + $scope.globalVariables.results = true; var initPoll = function () { - var pollPromise = Poll.get({pollId:$routeParams.pollId}, function (poll) { + var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) { $scope.data.poll = poll; }).$promise; diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html index e20217c..f77abba 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll.html @@ -24,15 +24,17 @@ <alert type="success" class="alert-float" ng-if="!globalVariables.editMode && globalVariables.saved" close="globalVariables.saved = false"> Vote effectué..</alert> <ul class="nav nav-tabs"> - <li ng-class="{active: tab == 'home'}" ng-click="tab = 'home'"><a href="{{url}}tab=home"> <span class="glyphicon glyphicon-home"></span> </a></li> - <li ng-class="{active: tab == 'poll'}" ng-click="tab = 'poll'"><a href="{{url}}tab=poll">Sondage</a></li> - <li ng-class="{active: tab == 'result'}" ng-click="tab = 'result'" ng-show="!globalVariables.create"><a href="{{url}}tab=result">Result</a></li> - <li ng-class="{active: tab == 'conf'}" ng-click="tab = 'conf'" ng-show="globalVariables.editMode"><a href="{{url}}tab=conf">Configuration</a></li> + <li ng-class="{active: tab == 'home'}"><a href="{{url}}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}}">Voter</a></li> + <li ng-class="{active: tab == 'result'}" ng-show="!globalVariables.create"><a href="{{url}}tab=result">Résultat</a></li> + <li ng-class="{active: tab == 'edit'}" ng-show="globalVariables.create"><a href="#/poll/create">Créer</a></li> + <li ng-class="{active: tab == 'edit'}" ng-show="data.poll.permission"><a href="{{globalVariables.linkEdit}}">Editer</a></li> + <li ng-class="{active: tab == 'conf'}" ng-show="data.poll.permission || globalVariables.create"><a href="{{url}}tab=conf">Configuration</a></li> </ul> <div ng-include="'partials/poll-link.html'" ng-if="tab == 'home'"></div> -<div ng-if="tab == 'poll'"> +<div ng-if="tab == 'edit' || tab == 'vote'"> <div class="pollTitle" edit-me="showEditTitle"> <h1 ng-hide="showEditTitle"> {{data.poll.title || 'Click pour éditer'}} -- To stop receiving notification emails like this one, please contact Chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
Chorem.org scm