From fb45d30a34a075609d92cdf9ad79cf4fe7cd479e Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Wed, 26 Apr 2017 16:09:27 +0200 Subject: [PATCH] Changed PDF documentProvider to accept images and some cleanup. --- openslides/agenda/static/js/agenda/pdf.js | 20 +- openslides/agenda/static/js/agenda/site.js | 13 +- .../assignments/static/js/assignments/pdf.js | 89 +- .../assignments/static/js/assignments/site.js | 64 +- .../assignments/assignment-detail.html | 4 +- .../assignments/assignment-list.html | 2 +- openslides/core/config_variables.py | 2 +- openslides/core/static/js/core/pdf-worker.js | 11 +- openslides/core/static/js/core/pdf.js | 84 +- .../templates/mediafiles/mediafile-list.html | 19 +- openslides/motions/static/js/motions/pdf.js | 1102 +++++++++-------- openslides/users/static/js/users/pdf.js | 207 ++-- openslides/users/static/js/users/site.js | 42 +- 13 files changed, 878 insertions(+), 781 deletions(-) diff --git a/openslides/agenda/static/js/agenda/pdf.js b/openslides/agenda/static/js/agenda/pdf.js index 841ba0364..28e957cef 100644 --- a/openslides/agenda/static/js/agenda/pdf.js +++ b/openslides/agenda/static/js/agenda/pdf.js @@ -75,6 +75,24 @@ angular.module('OpenSlidesApp.agenda.pdf', ['OpenSlidesApp.core.pdf']) createInstance: createInstance }; -}]); +}]) + +.factory('AgendaPdfExport', [ + 'gettextCatalog', + 'AgendaContentProvider', + 'PdfMakeDocumentProvider', + 'PdfCreate', + function (gettextCatalog, AgendaContentProvider, PdfMakeDocumentProvider, PdfCreate) { + return { + export: function (items) { + var filename = gettextCatalog.getString('Agenda') + '.pdf'; + var agendaContentProvider = AgendaContentProvider.createInstance(items); + PdfMakeDocumentProvider.createInstance(agendaContentProvider).then(function (documentProvider) { + PdfCreate.download(documentProvider.getDocument(), filename); + }); + }, + }; + } +]); }()); diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index 9d68f685a..73b04808e 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -89,17 +89,15 @@ angular.module('OpenSlidesApp.agenda.site', [ 'AgendaTree', 'Projector', 'ProjectionDefault', - 'AgendaContentProvider', - 'PdfMakeDocumentProvider', 'gettextCatalog', 'gettext', 'osTableFilter', 'AgendaCsvExport', - 'PdfCreate', + 'AgendaPdfExport', 'ErrorMessage', function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm, - AgendaTree, Projector, ProjectionDefault, AgendaContentProvider, PdfMakeDocumentProvider, - gettextCatalog, gettext, osTableFilter, AgendaCsvExport, PdfCreate, ErrorMessage) { + AgendaTree, Projector, ProjectionDefault, gettextCatalog, gettext, osTableFilter, + AgendaCsvExport, AgendaPdfExport, ErrorMessage) { // Bind agenda tree to the scope $scope.$watch(function () { return Agenda.lastModified(); @@ -276,10 +274,7 @@ angular.module('OpenSlidesApp.agenda.site', [ }; // export $scope.pdfExport = function () { - var filename = gettextCatalog.getString('Agenda') + '.pdf'; - var agendaContentProvider = AgendaContentProvider.createInstance($scope.itemsFiltered); - var documentProvider = PdfMakeDocumentProvider.createInstance(agendaContentProvider); - PdfCreate.download(documentProvider.getDocument(), filename); + AgendaPdfExport.export($scope.itemsFiltered); }; $scope.csvExport = function () { AgendaCsvExport.export($scope.itemsFiltered); diff --git a/openslides/assignments/static/js/assignments/pdf.js b/openslides/assignments/static/js/assignments/pdf.js index d27f36c48..4f5df21c8 100644 --- a/openslides/assignments/static/js/assignments/pdf.js +++ b/openslides/assignments/static/js/assignments/pdf.js @@ -259,10 +259,11 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf']) }; }; - return { - createInstance: createInstance - }; -}]) + return { + createInstance: createInstance + }; + } +]) .factory('BallotContentProvider', [ '$filter', @@ -271,12 +272,12 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf']) 'Config', 'User', function($filter, gettextCatalog, PDFLayout, Config, User) { - var createInstance = function(scope, poll, pollNumber) { + var createInstance = function(assignment, poll, pollNumber) { // page title var createTitle = function() { return { - text: scope.assignment.title, + text: assignment.title, style: 'title', }; }; @@ -477,10 +478,11 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf']) }; }; - return { - createInstance: createInstance - }; -}]) + return { + createInstance: createInstance + }; + } +]) .factory('AssignmentCatalogContentProvider', [ 'gettextCatalog', @@ -552,9 +554,68 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf']) }; }; - return { - createInstance: createInstance - }; -}]); + return { + createInstance: createInstance + }; + } +]) + +.factory('AssignmentPdfExport', [ + 'gettextCatalog', + 'AssignmentContentProvider', + 'AssignmentCatalogContentProvider', + 'PdfMakeDocumentProvider', + 'BallotContentProvider', + 'PdfMakeBallotPaperProvider', + 'PdfCreate', + function (gettextCatalog, AssignmentContentProvider, AssignmentCatalogContentProvider, + PdfMakeDocumentProvider, BallotContentProvider, PdfMakeBallotPaperProvider, PdfCreate) { + return { + export: function (assignments, singleAssignment) { + var filename = singleAssignment ? + gettextCatalog.getString('Election') + '_' + assignments.title : + gettextCatalog.getString('Elections'); + filename += '.pdf'; + if (singleAssignment) { + assignments = [assignments]; + } + var assignmentContentProviderArray = []; + + // Convert the assignments to content providers + angular.forEach(assignments, function(assignment) { + assignmentContentProviderArray.push(AssignmentContentProvider.createInstance(assignment)); + }); + + var documentProviderPromise; + if (singleAssignment) { + documentProviderPromise = + PdfMakeDocumentProvider.createInstance(assignmentContentProviderArray[0]); + } else { + var assignmentCatalogContentProvider = + AssignmentCatalogContentProvider.createInstance(assignmentContentProviderArray); + documentProviderPromise = + PdfMakeDocumentProvider.createInstance(assignmentCatalogContentProvider); + } + documentProviderPromise.then(function (documentProvider) { + PdfCreate.download(documentProvider.getDocument(), filename); + }); + }, + createBallotPdf: function (assignment, pollId) { + var thePoll; + var pollNumber; + angular.forEach(assignment.polls, function(poll, pollIndex) { + if (poll.id == pollId) { + thePoll = poll; + pollNumber = pollIndex+1; + } + }); + var filename = gettextCatalog.getString('Ballot') + '_' + pollNumber + '_' + assignment.title + '.pdf'; + var ballotContentProvider = BallotContentProvider.createInstance(assignment, thePoll, pollNumber); + var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider); + PdfCreate.download(documentProvider.getDocument(), filename); + }, + }; + } +]); }()); diff --git a/openslides/assignments/static/js/assignments/site.js b/openslides/assignments/static/js/assignments/site.js index 1a5416af6..6a639ce3f 100644 --- a/openslides/assignments/static/js/assignments/site.js +++ b/openslides/assignments/static/js/assignments/site.js @@ -265,18 +265,14 @@ angular.module('OpenSlidesApp.assignments.site', [ 'Projector', 'ProjectionDefault', 'gettextCatalog', - 'AssignmentContentProvider', - 'AssignmentCatalogContentProvider', - 'PdfMakeDocumentProvider', 'User', 'osTableFilter', 'osTableSort', 'gettext', - 'PdfCreate', 'AssignmentPhases', + 'AssignmentPdfExport', function($scope, ngDialog, AssignmentForm, Assignment, Tag, Agenda, Projector, ProjectionDefault, - gettextCatalog, AssignmentContentProvider, AssignmentCatalogContentProvider, PdfMakeDocumentProvider, - User, osTableFilter, osTableSort, gettext, PdfCreate, AssignmentPhases) { + gettextCatalog, User, osTableFilter, osTableSort, gettext, AssignmentPhases, AssignmentPdfExport) { Assignment.bindAll({}, $scope, 'assignments'); Tag.bindAll({}, $scope, 'tags'); $scope.$watch(function () { @@ -383,20 +379,8 @@ angular.module('OpenSlidesApp.assignments.site', [ Assignment.destroy(assignment.id); }; // create the PDF List - $scope.makePDF_assignmentList = function () { - var filename = gettextCatalog.getString("Elections") + ".pdf"; - var assignmentContentProviderArray = []; - - //convert the filtered assignments to content providers - angular.forEach($scope.assignmentsFiltered, function(assignment) { - assignmentContentProviderArray.push(AssignmentContentProvider.createInstance(assignment)); - }); - - var assignmentCatalogContentProvider = - AssignmentCatalogContentProvider.createInstance(assignmentContentProviderArray); - var documentProvider = - PdfMakeDocumentProvider.createInstance(assignmentCatalogContentProvider); - PdfCreate.download(documentProvider.getDocument(), filename); + $scope.pdfExport = function () { + AssignmentPdfExport.export($scope.assignmentsFiltered); }; } ]) @@ -416,18 +400,13 @@ angular.module('OpenSlidesApp.assignments.site', [ 'assignmentId', 'Projector', 'ProjectionDefault', - 'AssignmentContentProvider', - 'BallotContentProvider', - 'PdfMakeDocumentProvider', - 'PdfMakeBallotPaperProvider', 'gettextCatalog', - 'PdfCreate', 'AssignmentPhases', + 'AssignmentPdfExport', 'ErrorMessage', - function($scope, $http, $filter, $timeout, filterFilter, gettext, ngDialog, AssignmentForm, operator, Assignment, - User, assignmentId, Projector, ProjectionDefault, AssignmentContentProvider, BallotContentProvider, - PdfMakeDocumentProvider, PdfMakeBallotPaperProvider, gettextCatalog, PdfCreate, AssignmentPhases, - ErrorMessage) { + function($scope, $http, $filter, $timeout, filterFilter, gettext, ngDialog, AssignmentForm, operator, + Assignment, User, assignmentId, Projector, ProjectionDefault, gettextCatalog, AssignmentPhases, + AssignmentPdfExport, ErrorMessage) { User.bindAll({}, $scope, 'users'); var assignment = Assignment.get(assignmentId); Assignment.loadRelations(assignment, 'agenda_item'); @@ -600,28 +579,13 @@ angular.module('OpenSlidesApp.assignments.site', [ }; - //creates the document as pdf - $scope.makePDF_singleAssignment = function() { - var filename = gettextCatalog.getString("Election") + "_" + $scope.assignment.title + ".pdf"; - var assignmentContentProvider = AssignmentContentProvider.createInstance($scope.assignment); - var documentProvider = PdfMakeDocumentProvider.createInstance(assignmentContentProvider); - PdfCreate.download(documentProvider.getDocument(), filename); + // Creates the document as pdf + $scope.pdfExport = function() { + AssignmentPdfExport.export($scope.assignment, true); }; - - //creates the ballotpaper as pdf - $scope.makePDF_assignmentpoll = function(pollID) { - var thePoll; - var pollNumber; - angular.forEach($scope.assignment.polls, function(poll, pollIndex) { - if (poll.id == pollID) { - thePoll = poll; - pollNumber = pollIndex+1; - } - }); - var filename = gettextCatalog.getString("Ballot") + "_" + pollNumber + "_" + $scope.assignment.title + ".pdf"; - var ballotContentProvider = BallotContentProvider.createInstance($scope, thePoll, pollNumber); - var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider); - PdfCreate.download(documentProvider.getDocument(), filename); + // Creates the ballotpaper as pdf + $scope.ballotpaperExport = function(pollId) { + AssignmentPdfExport.createBallotPdf($scope.assignment, pollId); }; // Just mark some vote value strings for translation. diff --git a/openslides/assignments/static/templates/assignments/assignment-detail.html b/openslides/assignments/static/templates/assignments/assignment-detail.html index d9b40a250..28cd8787d 100644 --- a/openslides/assignments/static/templates/assignments/assignment-detail.html +++ b/openslides/assignments/static/templates/assignments/assignment-detail.html @@ -21,7 +21,7 @@ - + PDF @@ -152,7 +152,7 @@ - + Print ballot paper diff --git a/openslides/assignments/static/templates/assignments/assignment-list.html b/openslides/assignments/static/templates/assignments/assignment-list.html index d8f61a412..313bf9802 100644 --- a/openslides/assignments/static/templates/assignments/assignment-list.html +++ b/openslides/assignments/static/templates/assignments/assignment-list.html @@ -39,7 +39,7 @@