From ff840ab3c6166657b55f8b3b39d016cca4bee1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Sch=C3=BCtze?= Date: Sat, 4 Mar 2017 21:38:25 +0100 Subject: [PATCH] Excluded already elected persons for new ballot (Fixed #2142) - Reorder assignment ballot tabs in detail template. - Removed logic to set phase automatically to 'finished' if elected candidates reached, because autoupdate makes it unreliable. --- openslides/assignments/models.py | 2 +- .../assignments/static/js/assignments/site.js | 32 ++++++++++--------- .../assignments/assignment-detail.html | 5 ++- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/openslides/assignments/models.py b/openslides/assignments/models.py index 8f51dfb56..ae0f81dae 100644 --- a/openslides/assignments/models.py +++ b/openslides/assignments/models.py @@ -272,7 +272,7 @@ class Assignment(RESTModelMixin, models.Model): description=self.poll_description_default, pollmethod=pollmethod) options = [] - related_users = AssignmentRelatedUser.objects.filter(assignment__id=self.id) + related_users = AssignmentRelatedUser.objects.filter(assignment__id=self.id).exclude(elected=True) for related_user in related_users: options.append({ 'candidate': related_user.user, diff --git a/openslides/assignments/static/js/assignments/site.js b/openslides/assignments/static/js/assignments/site.js index 5a4558ab1..76ef872f6 100644 --- a/openslides/assignments/static/js/assignments/site.js +++ b/openslides/assignments/static/js/assignments/site.js @@ -405,6 +405,7 @@ angular.module('OpenSlidesApp.assignments.site', [ '$scope', '$http', '$filter', + '$timeout', 'filterFilter', 'gettext', 'ngDialog', @@ -423,7 +424,7 @@ angular.module('OpenSlidesApp.assignments.site', [ 'PdfCreate', 'AssignmentPhases', 'ErrorMessage', - function($scope, $http, $filter, filterFilter, gettext, ngDialog, AssignmentForm, operator, Assignment, + function($scope, $http, $filter, $timeout, filterFilter, gettext, ngDialog, AssignmentForm, operator, Assignment, User, assignmentId, Projector, ProjectionDefault, AssignmentContentProvider, BallotContentProvider, PdfMakeDocumentProvider, PdfMakeBallotPaperProvider, gettextCatalog, PdfCreate, AssignmentPhases, ErrorMessage) { @@ -448,7 +449,7 @@ angular.module('OpenSlidesApp.assignments.site', [ $scope.candidateSelectBox = {}; $scope.phases = AssignmentPhases; $scope.alert = {}; - $scope.activeTab = 0; + $scope.activeTab = assignment.polls.length - 1; // open edit dialog $scope.openDialog = function (assignment) { @@ -527,20 +528,30 @@ angular.module('OpenSlidesApp.assignments.site', [ }; // create new ballot $scope.createBallot = function () { - $scope.activeTab = 0; $http.post('/rest/assignments/assignment/' + assignment.id + '/create_poll/').then( function (success) { $scope.alert.show = false; if (assignment.phase === 0) { $scope.updatePhase(1); } + // set 'activeTab' to recently added (last) ballot tab + // TODO: $timeout is required, see + // https://github.com/angular-ui/bootstrap/issues/5656 + $timeout(function() { + $scope.activeTab = assignment.polls.length - 1; + }, 0); }, function (error) { $scope.alert = ErrorMessage.forAlert(error); - }); + } + ); }; // delete ballot $scope.deleteBallot = function (poll) { - poll.DSDestroy(); + poll.DSDestroy().then( + function (success) { + $scope.activeTab = assignment.polls.length - 1; + } + ); }; // edit poll dialog $scope.editPollDialog = function (poll, ballot) { @@ -582,16 +593,7 @@ angular.module('OpenSlidesApp.assignments.site', [ } ); } else { - $http.post('/rest/assignments/assignment/' + assignment.id + '/mark_elected/', {'user': user}) - .then(function(success) { - var elected = filterFilter(assignment.assignment_related_users,{elected: true}); - // Set phase to 'finished' if there are enough (= number of open posts) elected users. - // Note: The array 'elected' does NOT contains the candidate who is just marked as elected. - // So add 1 to length to get the real number of all elected users. - if (elected.length + 1 == assignment.open_posts ) { - $scope.updatePhase(2); - } - }); + $http.post('/rest/assignments/assignment/' + assignment.id + '/mark_elected/', {'user': user}); } }; diff --git a/openslides/assignments/static/templates/assignments/assignment-detail.html b/openslides/assignments/static/templates/assignments/assignment-detail.html index 6b9f55367..a3e21ceca 100644 --- a/openslides/assignments/static/templates/assignments/assignment-detail.html +++ b/openslides/assignments/static/templates/assignments/assignment-detail.html @@ -126,10 +126,9 @@ New ballot - - +