Merge pull request #3113 from FinnStutzenstein/assignment-tabs

Fixes Ballot tabs on create/delete (fixes #3058)
This commit is contained in:
Norman Jäckel 2017-03-21 17:22:15 +01:00 committed by GitHub
commit c39d003f01
2 changed files with 36 additions and 34 deletions

View File

@ -428,9 +428,13 @@ angular.module('OpenSlidesApp.assignments.site', [
User, assignmentId, Projector, ProjectionDefault, AssignmentContentProvider, BallotContentProvider, User, assignmentId, Projector, ProjectionDefault, AssignmentContentProvider, BallotContentProvider,
PdfMakeDocumentProvider, PdfMakeBallotPaperProvider, gettextCatalog, PdfCreate, AssignmentPhases, PdfMakeDocumentProvider, PdfMakeBallotPaperProvider, gettextCatalog, PdfCreate, AssignmentPhases,
ErrorMessage) { ErrorMessage) {
var assignment = Assignment.get(assignmentId);
User.bindAll({}, $scope, 'users'); User.bindAll({}, $scope, 'users');
var assignment = Assignment.get(assignmentId);
Assignment.loadRelations(assignment, 'agenda_item'); Assignment.loadRelations(assignment, 'agenda_item');
// This flag is for setting 'activeTab' to recently added (last) ballot tab.
// Set this flag, if ballots are added/removed. When the next autoupdate comes
// in, the tabset will be updated.
var updateBallotTabsFlag = true;
$scope.$watch(function () { $scope.$watch(function () {
return Projector.lastModified(); return Projector.lastModified();
}, function () { }, function () {
@ -440,24 +444,27 @@ angular.module('OpenSlidesApp.assignments.site', [
} }
}); });
$scope.$watch(function () { $scope.$watch(function () {
return Assignment.lastModified(assignment.id); return Assignment.lastModified(assignmentId);
}, function () { }, function () {
// setup sorting of candidates // setup sorting of candidates
$scope.relatedUsersSorted = $filter('orderBy')(assignment.assignment_related_users, 'weight'); $scope.relatedUsersSorted = $filter('orderBy')(assignment.assignment_related_users, 'weight');
$scope.assignment = Assignment.get(assignment.id); $scope.assignment = Assignment.get(assignment.id);
if (updateBallotTabsFlag) {
$scope.activeTab = $scope.assignment.polls.length - 1;
updateBallotTabsFlag = false;
}
}); });
$scope.candidateSelectBox = {}; $scope.candidateSelectBox = {};
$scope.phases = AssignmentPhases; $scope.phases = AssignmentPhases;
$scope.alert = {}; $scope.alert = {};
$scope.activeTab = assignment.polls.length - 1;
// open edit dialog // open edit dialog
$scope.openDialog = function (assignment) { $scope.openDialog = function () {
ngDialog.open(AssignmentForm.getDialog(assignment)); ngDialog.open(AssignmentForm.getDialog($scope.assignment));
}; };
// add (nominate) candidate // add (nominate) candidate
$scope.addCandidate = function (userId) { $scope.addCandidate = function (userId) {
$http.post('/rest/assignments/assignment/' + assignment.id + '/candidature_other/', {'user': userId}) $http.post('/rest/assignments/assignment/' + assignmentId + '/candidature_other/', {'user': userId})
.then(function (success){ .then(function (success){
$scope.alert.show = false; $scope.alert.show = false;
$scope.candidateSelectBox = {}; $scope.candidateSelectBox = {};
@ -468,7 +475,7 @@ angular.module('OpenSlidesApp.assignments.site', [
}; };
// remove candidate // remove candidate
$scope.removeCandidate = function (userId) { $scope.removeCandidate = function (userId) {
$http.delete('/rest/assignments/assignment/' + assignment.id + '/candidature_other/', $http.delete('/rest/assignments/assignment/' + assignmentId + '/candidature_other/',
{headers: {'Content-Type': 'application/json'}, {headers: {'Content-Type': 'application/json'},
data: JSON.stringify({user: userId})}) data: JSON.stringify({user: userId})})
.then(function (success) {}, .then(function (success) {},
@ -479,7 +486,7 @@ angular.module('OpenSlidesApp.assignments.site', [
}; };
// add me (nominate self as candidate) // add me (nominate self as candidate)
$scope.addMe = function () { $scope.addMe = function () {
$http.post('/rest/assignments/assignment/' + assignment.id + '/candidature_self/', {}).then( $http.post('/rest/assignments/assignment/' + assignmentId + '/candidature_self/', {}).then(
function (success) { function (success) {
$scope.alert.show = false; $scope.alert.show = false;
}, function (error) { }, function (error) {
@ -489,7 +496,7 @@ angular.module('OpenSlidesApp.assignments.site', [
}; };
// remove me (withdraw own candidature) // remove me (withdraw own candidature)
$scope.removeMe = function () { $scope.removeMe = function () {
$http.delete('/rest/assignments/assignment/' + assignment.id + '/candidature_self/').then( $http.delete('/rest/assignments/assignment/' + assignmentId + '/candidature_self/').then(
function (success) { function (success) {
$scope.alert.show = false; $scope.alert.show = false;
}, function (error) { }, function (error) {
@ -499,15 +506,16 @@ angular.module('OpenSlidesApp.assignments.site', [
}; };
// check if current user is already a candidate (elected==false) // check if current user is already a candidate (elected==false)
$scope.isCandidate = function () { $scope.isCandidate = function () {
var check = assignment.assignment_related_users.map( function(candidate) { var check = $scope.assignment.assignment_related_users.map(function(candidate) {
if ( !candidate.elected ) { if (!candidate.elected) {
return candidate.user_id; return candidate.user_id;
} }
}).indexOf(operator.user.id); }).indexOf(operator.user.id);
if (check > -1) if (check > -1) {
return true; return true;
else } else {
return false; return false;
}
}; };
// Sort all candidates // Sort all candidates
$scope.treeOptions = { $scope.treeOptions = {
@ -516,30 +524,25 @@ angular.module('OpenSlidesApp.assignments.site', [
_.forEach($scope.relatedUsersSorted, function (user) { _.forEach($scope.relatedUsersSorted, function (user) {
sortedCandidates.push(user.id); sortedCandidates.push(user.id);
}); });
$http.post('/rest/assignments/assignment/' + $scope.assignment.id + '/sort_related_users/', $http.post('/rest/assignments/assignment/' + assignmentId + '/sort_related_users/',
{related_users: sortedCandidates} {related_users: sortedCandidates}
); );
} }
}; };
// update phase // update phase
$scope.updatePhase = function (phase_id) { $scope.updatePhase = function (phase_id) {
assignment.phase = phase_id; $scope.assignment.phase = phase_id;
Assignment.save(assignment); Assignment.save($scope.assignment);
}; };
// create new ballot // create new ballot
$scope.createBallot = function () { $scope.createBallot = function () {
$http.post('/rest/assignments/assignment/' + assignment.id + '/create_poll/').then( $http.post('/rest/assignments/assignment/' + assignmentId + '/create_poll/').then(
function (success) { function (success) {
$scope.alert.show = false; $scope.alert.show = false;
if (assignment.phase === 0) { if (assignment.phase === 0) {
$scope.updatePhase(1); $scope.updatePhase(1);
} }
// set 'activeTab' to recently added (last) ballot tab updateBallotTabsFlag = true;
// TODO: $timeout is required, see
// https://github.com/angular-ui/bootstrap/issues/5656
$timeout(function() {
$scope.activeTab = assignment.polls.length - 1;
}, 0);
}, function (error) { }, function (error) {
$scope.alert = ErrorMessage.forAlert(error); $scope.alert = ErrorMessage.forAlert(error);
} }
@ -549,7 +552,8 @@ angular.module('OpenSlidesApp.assignments.site', [
$scope.deleteBallot = function (poll) { $scope.deleteBallot = function (poll) {
poll.DSDestroy().then( poll.DSDestroy().then(
function (success) { function (success) {
$scope.activeTab = assignment.polls.length - 1; $scope.activeTab = $scope.activeTab - 1;
updateBallotTabsFlag = true;
} }
); );
}; };
@ -570,7 +574,7 @@ angular.module('OpenSlidesApp.assignments.site', [
// publish ballot // publish ballot
$scope.togglePublishBallot = function (poll) { $scope.togglePublishBallot = function (poll) {
poll.DSUpdate({ poll.DSUpdate({
assignment_id: assignment.id, assignment_id: assignmentId,
published: !poll.published, published: !poll.published,
}) })
.then(function (success) { .then(function (success) {
@ -584,16 +588,14 @@ angular.module('OpenSlidesApp.assignments.site', [
$scope.markElected = function (user, reverse) { $scope.markElected = function (user, reverse) {
if (reverse) { if (reverse) {
$http.delete( $http.delete(
'/rest/assignments/assignment/' + assignment.id + '/mark_elected/', '/rest/assignments/assignment/' + assignmentId + '/mark_elected/', {
{
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
data: JSON.stringify({user: user}) data: JSON.stringify({user: user})
} });
);
} else { } else {
$http.post('/rest/assignments/assignment/' + assignment.id + '/mark_elected/', {'user': user}); $http.post('/rest/assignments/assignment/' + assignmentId + '/mark_elected/', {'user': user});
} }
}; };
@ -601,7 +603,7 @@ angular.module('OpenSlidesApp.assignments.site', [
//creates the document as pdf //creates the document as pdf
$scope.makePDF_singleAssignment = function() { $scope.makePDF_singleAssignment = function() {
var filename = gettextCatalog.getString("Election") + "_" + $scope.assignment.title + ".pdf"; var filename = gettextCatalog.getString("Election") + "_" + $scope.assignment.title + ".pdf";
var assignmentContentProvider = AssignmentContentProvider.createInstance(assignment); var assignmentContentProvider = AssignmentContentProvider.createInstance($scope.assignment);
var documentProvider = PdfMakeDocumentProvider.createInstance(assignmentContentProvider); var documentProvider = PdfMakeDocumentProvider.createInstance(assignmentContentProvider);
PdfCreate.download(documentProvider.getDocument(), filename); PdfCreate.download(documentProvider.getDocument(), filename);
}; };
@ -610,7 +612,7 @@ angular.module('OpenSlidesApp.assignments.site', [
$scope.makePDF_assignmentpoll = function(pollID) { $scope.makePDF_assignmentpoll = function(pollID) {
var thePoll; var thePoll;
var pollNumber; var pollNumber;
angular.forEach(assignment.polls, function(poll, pollIndex) { angular.forEach($scope.assignment.polls, function(poll, pollIndex) {
if (poll.id == pollID) { if (poll.id == pollID) {
thePoll = poll; thePoll = poll;
pollNumber = pollIndex+1; pollNumber = pollIndex+1;

View File

@ -15,7 +15,7 @@
<projector-button model="assignment", default-projector-id="defaultProjectorId"> <projector-button model="assignment", default-projector-id="defaultProjectorId">
</projector-button> </projector-button>
<!-- edit --> <!-- edit -->
<a os-perms="assignments.can_manage" ng-click="openDialog(assignment)" <a os-perms="assignments.can_manage" ng-click="openDialog()"
class="btn btn-default btn-sm" class="btn btn-default btn-sm"
title="{{ 'Edit' | translate}}"> title="{{ 'Edit' | translate}}">
<i class="fa fa-pencil"></i> <i class="fa fa-pencil"></i>
@ -127,7 +127,7 @@
<i class="fa fa-bar-chart fa-lg"></i> <i class="fa fa-bar-chart fa-lg"></i>
<translate>New ballot</translate> <translate>New ballot</translate>
</button> </button>
<uib-tabset ng-if="assignment.polls.length > 0" class="spacer ballot-tabs" active="activeTab"> <uib-tabset ng-if="assignment.polls.length > 0" class="spacer ballot-tabs" active="$parent.activeTab">
<uib-tab ng-repeat="poll in assignment.polls | orderBy:'id'" <uib-tab ng-repeat="poll in assignment.polls | orderBy:'id'"
index="$index" heading="{{ 'Ballot' | translate }} {{ $index + 1 }}"> index="$index" heading="{{ 'Ballot' | translate }} {{ $index + 1 }}">
<div ng-controller="AssignmentPollDetailCtrl"> <div ng-controller="AssignmentPollDetailCtrl">