Fix publish assignment poll function.

Set 'votes' to required=False in AssignmentAllPollSerializer.
This commit is contained in:
Emanuel Schuetze 2015-12-18 20:18:03 +01:00
parent 99b4e8c494
commit 6b8aa56e87
3 changed files with 27 additions and 19 deletions

View File

@ -79,7 +79,8 @@ class AssignmentAllPollSerializer(ModelSerializer):
votes = ListField(
child=DictField(
child=IntegerField(min_value=-2)),
write_only=True)
write_only=True,
required=False)
class Meta:
model = AssignmentPoll

View File

@ -235,12 +235,13 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
.controller('AssignmentDetailCtrl', [
'$scope',
'$http',
'gettext',
'ngDialog',
'operator',
'Assignment',
'User',
'assignment',
function($scope, $http, ngDialog, operator, Assignment, User, assignment) {
function($scope, $http, gettext, ngDialog, operator, Assignment, User, assignment) {
User.bindAll({}, $scope, 'users');
Assignment.bindOne(assignment.id, $scope, 'assignment');
Assignment.loadRelations(assignment, 'agenda_item');
@ -336,15 +337,21 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
});
};
// publish ballot
$scope.publishBallot = function () {
// TODO poll.DSUpdate()
$http.put('/rest/assignments/assignment/' + assignment.id + '/publish_poll/')
.success(function(data){
$scope.alert.show = false;
})
.error(function(data){
$scope.alert = { type: 'danger', msg: data.detail, show: true };
});
$scope.publishBallot = function (poll, isPublished) {
poll.DSUpdate({
assignment_id: assignment.id,
published: isPublished,
})
.then(function(success) {
$scope.alert.show = false;
})
.catch(function(error) {
var message = '';
for (var e in error.data) {
message += e + ': ' + error.data[e] + ' ';
}
$scope.alert = { type: 'danger', msg: message, show: true };
});
};
// Just mark some vote value strings for translation.

View File

@ -97,15 +97,15 @@
class="btn btn-default btn-sm">
<i class="fa fa-file-pdf-o"></i> Ballot paper
</a>
<button os-perms-lite="assignments.can_manage" ng-if="!poll.published" ng-click="publishBallot(poll)"
class="btn btn-primary btn-sm">
<i class="fa fa-globe"></i>
<translate>Publish result</translate>
</button>
<button os-perms-lite="assignments.can_manage" ng-if="poll.published" ng-click="unpublishBallot(poll)"
<button os-perms-lite="assignments.can_manage" ng-if="!poll.published" ng-click="publishBallot(poll, true)"
class="btn btn-default btn-sm">
<i class="fa fa-globe"></i>
<translate>Unpublish result</translate>
<i class="fa fa-toggle-off"></i>
<translate>Not published</translate>
</button>
<button os-perms-lite="assignments.can_manage" ng-if="poll.published" ng-click="publishBallot(poll, false)"
class="btn btn-default btn-sm">
<i class="fa fa-toggle-on"></i>
<translate>Published</translate>
</button>
<a ng-click="deleteBallot(poll)" class="btn btn-default btn-sm">
<i class="fa fa-times"></i>