From 731b329385aeacd346af6b180858aaa60163881a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Sch=C3=BCtze?= Date: Wed, 11 Jan 2017 22:06:11 +0100 Subject: [PATCH] CUSTOM: Adapt election ballot pdf. --- .../assignments/static/js/assignments/pdf.js | 154 ++++++++++++++++++ .../assignments/static/js/assignments/site.js | 6 +- openslides/core/static/js/core/pdf.js | 14 +- 3 files changed, 165 insertions(+), 9 deletions(-) diff --git a/openslides/assignments/static/js/assignments/pdf.js b/openslides/assignments/static/js/assignments/pdf.js index d27f36c489..7f01e97eef 100644 --- a/openslides/assignments/static/js/assignments/pdf.js +++ b/openslides/assignments/static/js/assignments/pdf.js @@ -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', diff --git a/openslides/assignments/static/js/assignments/site.js b/openslides/assignments/static/js/assignments/site.js index 7b1618ddb2..53ec721d75 100644 --- a/openslides/assignments/static/js/assignments/site.js +++ b/openslides/assignments/static/js/assignments/site.js @@ -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'); @@ -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); }; diff --git a/openslides/core/static/js/core/pdf.js b/openslides/core/static/js/core/pdf.js index fecf9f15fc..b67ceef2b1 100644 --- a/openslides/core/static/js/core/pdf.js +++ b/openslides/core/static/js/core/pdf.js @@ -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], } } };