diff --git a/openslides/agenda/static/js/agenda/pdf.js b/openslides/agenda/static/js/agenda/pdf.js new file mode 100644 index 000000000..6aee41d9b --- /dev/null +++ b/openslides/agenda/static/js/agenda/pdf.js @@ -0,0 +1,80 @@ +(function () { + +'use strict'; + +angular.module('OpenSlidesApp.agenda.pdf', ['OpenSlidesApp.core.pdf']) + +.factory('AgendaContentProvider', [ + 'gettextCatalog', + 'PdfPredefinedFunctions', + function(gettextCatalog, PdfPredefinedFunctions) { + + var createInstance = function(items) { + + //use the Predefined Functions to create the title + var title = PdfPredefinedFunctions.createTitle(gettextCatalog.getString("Agenda")); + + //function to generate the item list out of the given "items" object + var createItemList = function() { + var agenda_items = []; + angular.forEach(items, function (item) { + if (item.is_hidden === false) { + + var itemIndent = item.parentCount * 20; + + var itemStyle; + if (item.parentCount === 0) { + itemStyle = 'listParent'; + } else { + itemStyle = 'listChild'; + } + + var itemNumberWidth; + if (item.item_number === "") { + itemNumberWidth = 0; + } else { + itemNumberWidth = 60; + } + + var agendaJsonString = { + style: itemStyle, + columns: [ + { + width: itemIndent, + text: '' + }, + { + width: itemNumberWidth, + text: item.item_number + }, + { + text: item.title + } + ] + }; + + agenda_items.push(agendaJsonString); + } + }); + return agenda_items; + }; + + var getContent = function() { + return [ + title, + createItemList() + ]; + }; + + return { + getContent: getContent + }; + }; + + return { + createInstance: createInstance + }; + +}]); + +}()); diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index 5f1dca7d3..eaf11eff1 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -2,7 +2,11 @@ 'use strict'; -angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) +angular.module('OpenSlidesApp.agenda.site', [ + 'OpenSlidesApp.agenda', + 'OpenSlidesApp.core.pdf', + 'OpenSlidesApp.agenda.pdf' +]) .config([ 'mainMenuProvider', @@ -100,7 +104,11 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) 'AgendaTree', 'Projector', 'ProjectionDefault', - function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm, AgendaTree, Projector, ProjectionDefault) { + 'AgendaContentProvider', + 'PdfMakeDocumentProvider', + 'gettextCatalog', + function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm, AgendaTree, Projector, + ProjectionDefault, AgendaContentProvider, PdfMakeDocumentProvider, gettextCatalog) { // Bind agenda tree to the scope $scope.$watch(function () { return Agenda.lastModified(); @@ -307,6 +315,13 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) $scope.autoNumbering = function() { $http.post('/rest/agenda/item/numbering/', {}); }; + + $scope.makePDF = function() { + var filename = gettextCatalog.getString("Agenda")+".pdf"; + var agendaContentProvider = AgendaContentProvider.createInstance($scope.items); + var documentProvider = PdfMakeDocumentProvider.createInstance(agendaContentProvider); + pdfMake.createPdf(documentProvider.getDocument()).download(filename); + }; } ]) diff --git a/openslides/agenda/static/templates/agenda/item-list.html b/openslides/agenda/static/templates/agenda/item-list.html index a78df62fd..65afc5dde 100644 --- a/openslides/agenda/static/templates/agenda/item-list.html +++ b/openslides/agenda/static/templates/agenda/item-list.html @@ -23,7 +23,7 @@