Skip to content

Commit

Permalink
CUSTOM: Adapt election ballot pdf.
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelschuetze committed Jan 11, 2017
1 parent 7f4fc84 commit 731b329
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 9 deletions.
154 changes: 154 additions & 0 deletions openslides/assignments/static/js/assignments/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,160 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
};
}])

.factory('BallotContentProviderA5', [
'$filter',
'gettextCatalog',
'PDFLayout',
'Config',
'User',
function($filter, gettextCatalog, PDFLayout, Config, User) {
var createInstance = function(scope, poll, pollNumber) {

// PDF header
var header = function() {
var columns = [];

var line1 = [
Config.get('general_event_name').value,
Config.get('general_event_description').value
].filter(Boolean).join(' – ');
var line2 = [
Config.get('general_event_location').value,
Config.get('general_event_date').value
].filter(Boolean).join(', ');
var text = [line1, line2].join('\n');
columns.push({
text: text,
fontSize:10,
alignment: 'left',
margin: [0, 10, 0, 0],
width: '80%'
});

// logo
columns.push({
image: 'logo-pdf.png',
fit: [180,60],
width: '20%'
});
return {
color: '#555',
fontSize: 10,
margin: [0, 20, 20, 20], // [left, top, right, bottom]
columns: columns,
columnGap: 5
};
};

// ballot title
var createTitle = function() {
return {
text: "Stimmzettel für die Wahl:\n" + scope.assignment.title,
fontSize: 20,
bold: true,
margin: [208,0,100,0]
};
};

var createBallotNumber = function() {
return {
text: pollNumber + "." + gettextCatalog.getString("Ballot"),
fontSize: 20,
bold: false,
margin: [208, 0, 100, 40]
};
};

// election entries
var createYNBallotEntry = function(decision) {
var YNColumn = [
{
width: "auto",
stack: [
PDFLayout.createBallotEntry(gettextCatalog.getString("Yes"))
]
},
{
width: "auto",
stack: [
PDFLayout.createBallotEntry(gettextCatalog.getString("No"))
]
},
];

if (poll.pollmethod == 'yna') {
YNColumn.push({
width: "auto",
stack: [
PDFLayout.createBallotEntry(gettextCatalog.getString("Abstain"))
]
});
}

return [
{
columns: [
{
text: decision,
margin: [0, 10, 0, 0],
width: "31%"
},
{
columns: YNColumn
}
]
}
];
};

var createSelectionField = function() {
var candidates = $filter('orderBy')(poll.options, 'weight');
var candidateBallotList = [];

if (poll.pollmethod == 'votes') {
angular.forEach(candidates, function(option) {
var candidate = option.candidate.get_full_name();
candidateBallotList.push(PDFLayout.createBallotEntry(candidate));
});
} else {
angular.forEach(candidates, function(option) {
var candidate = option.candidate.get_full_name();
candidateBallotList.push(createYNBallotEntry(candidate));
});
}
return candidateBallotList;
};

var getContent = function() {
return [
header(),
createTitle(),
createBallotNumber(),
createSelectionField(),
];
};

var getFooter = function() {
var description = "";
if (poll.description)
description = poll.description;
return {
text: description,
style: "description"
};
};

return {
getContent: getContent,
getFooter: getFooter
};
};

return {
createInstance: createInstance
};
}])

.factory('AssignmentCatalogContentProvider', [
'gettextCatalog',
'PDFLayout',
Expand Down
6 changes: 3 additions & 3 deletions openslides/assignments/static/js/assignments/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,12 @@ angular.module('OpenSlidesApp.assignments.site', [
'Projector',
'ProjectionDefault',
'AssignmentContentProvider',
'BallotContentProvider',
'BallotContentProviderA5',
'PdfMakeDocumentProvider',
'PdfMakeBallotPaperProvider',
'gettextCatalog',
function($scope, $http, $filter, filterFilter, gettext, ngDialog, AssignmentForm, operator, Assignment,
User, assignment, phases, Projector, ProjectionDefault, AssignmentContentProvider, BallotContentProvider,
User, assignment, phases, Projector, ProjectionDefault, AssignmentContentProvider, BallotContentProviderA5,
PdfMakeDocumentProvider, PdfMakeBallotPaperProvider, gettextCatalog) {
User.bindAll({}, $scope, 'users');
Assignment.loadRelations(assignment, 'agenda_item');
Expand Down Expand Up @@ -656,7 +656,7 @@ angular.module('OpenSlidesApp.assignments.site', [
}
});
var filename = gettextCatalog.getString("Ballot") + "_" + pollNumber + "_" + $scope.assignment.title + ".pdf";
var ballotContentProvider = BallotContentProvider.createInstance($scope, thePoll, pollNumber);
var ballotContentProvider = BallotContentProviderA5.createInstance($scope, thePoll, pollNumber);
var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider);
pdfMake.createPdf(documentProvider.getDocument()).download(filename);
};
Expand Down
14 changes: 8 additions & 6 deletions openslides/core/static/js/core/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,24 @@ angular.module('OpenSlidesApp.core.pdf', [])
var getDocument = function() {
var content = contentProvider.getContent();
return {
pageSize: 'A4',
pageMargins: [0, 0, 0, 0],
pageSize: 'A5',
pageOrientation: 'landscape',
pageMargins: [40, 10, 10, 30],
defaultStyle: {
font: PDFLayout.getFontName(),
fontSize: 10
fontSize: 14
},
content: content,
footer: contentProvider.getFooter(),
content: contentProvider.getContent(),
styles: {
title: {
fontSize: 14,
bold: true,
margin: [30, 30, 0, 0]
margin: [0, 30, 0, 0]
},
description: {
fontSize: 11,
margin: [30, 0, 0, 0]
margin: [40, 0, 0, 0],
}
}
};
Expand Down

0 comments on commit 731b329

Please sign in to comment.