diff --git a/openslides/core/static/js/core/pdf.js b/openslides/core/static/js/core/pdf.js index 1e681aaa0..fa2e01154 100644 --- a/openslides/core/static/js/core/pdf.js +++ b/openslides/core/static/js/core/pdf.js @@ -129,6 +129,15 @@ angular.module('OpenSlidesApp.core.pdf', []) listChild: { fontSize: 11, margin: [0,5] + }, + tableHeader: { + bold: true + }, + tableEven: { + fillColor: 'white' + }, + tableOdd: { + fillColor: '#e7e7e7' } } }; diff --git a/openslides/users/static/js/users/pdf.js b/openslides/users/static/js/users/pdf.js new file mode 100644 index 000000000..8a1a9364a --- /dev/null +++ b/openslides/users/static/js/users/pdf.js @@ -0,0 +1,116 @@ +(function () { + +'use strict'; + +angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf']) + +.factory('UserListContentProvider', [ + 'gettextCatalog', + 'PdfPredefinedFunctions', + function(gettextCatalog, PdfPredefinedFunctions) { + + var createInstance = function(userList, groups) { + + //use the Predefined Functions to create the title + var title = PdfPredefinedFunctions.createTitle(gettextCatalog.getString("List of participants")); + + //function to generate the user list + var createUserList = function() { + var userJsonList = []; + + angular.forEach(userList, function (user, counter) { + + //check if the row is even or odd + var rowStyle = []; + if (counter % 2 === 0) { + rowStyle = 'tableEven'; + } else { + rowStyle = 'tableOdd'; + } + + //parse for the group names + var userGroups = []; + angular.forEach(user.groups_id, function (id) { + if (id) { + angular.forEach(groups, function(group) { + if (id == group.id) { + userGroups.push(gettextCatalog.getString(group.name)); + } + }); + } + }); + + var userJsonObj = [ + { + text: "" + (counter+1), + style: rowStyle + }, + { + text: user.short_name, + style: rowStyle + }, + { + text: user.structure_level, + style: rowStyle + }, + { + text: userGroups.join(" "), + style: rowStyle + } + ]; + userJsonList.push(userJsonObj); + }); + + var userTableBody = [ + [ + { + text: '#', + style: 'tableHeader' + }, + { + text: gettextCatalog.getString("Name"), + style: 'tableHeader' + }, + { + text: gettextCatalog.getString("Structure level"), + style: 'tableHeader' + }, + { + text: gettextCatalog.getString("Groups"), + style: 'tableHeader' + } + ] + ]; + userTableBody = userTableBody.concat((userJsonList)); + + var userTableJsonString = { + table: { + widths: ['auto', '*', 'auto', 'auto'], + headerRows: 1, + body: userTableBody + }, + layout: 'headerLineOnly' + }; + + return userTableJsonString; + }; + + var getContent = function() { + return [ + title, + createUserList() + ]; + }; + + return { + getContent: getContent + }; + }; + + return { + createInstance: createInstance + }; + +}]); + +}()); diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js index 84918334b..1beb73e49 100644 --- a/openslides/users/static/js/users/site.js +++ b/openslides/users/static/js/users/site.js @@ -2,7 +2,11 @@ 'use strict'; -angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) +angular.module('OpenSlidesApp.users.site', [ + 'OpenSlidesApp.users', + 'OpenSlidesApp.core.pdf', + 'OpenSlidesApp.users.pdf' +]) .config([ 'mainMenuProvider', @@ -423,7 +427,11 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) 'PasswordGenerator', 'Projector', 'ProjectionDefault', - function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault) { + 'UserListContentProvider', + 'PdfMakeDocumentProvider', + 'gettextCatalog', + function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault, + UserListContentProvider, PdfMakeDocumentProvider, gettextCatalog) { User.bindAll({}, $scope, 'users'); Group.bindAll({where: {id: {'>': 1}}}, $scope, 'groups'); $scope.$watch(function () { @@ -548,6 +556,13 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) $scope.isSelectMode = false; $scope.uncheckAll(); }; + + $scope.makePDF_userList = function () { + var filename = gettextCatalog.getString("List of participants")+".pdf"; + var userListContentProvider = UserListContentProvider.createInstance($scope.users, $scope.groups); + var documentProvider = PdfMakeDocumentProvider.createInstance(userListContentProvider); + pdfMake.createPdf(documentProvider.getDocument()).download(filename); + }; } ]) @@ -959,7 +974,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) existingUsers.forEach(function(user_) { if (user_.first_name == user.first_name && user_.last_name == user.last_name && - user_.structure_level == user.structure_level) { + user_.structure_level == user.structure_level) { deletePromises.push(User.destroy(user_.id)); } }); @@ -968,7 +983,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) function(success) { user.imported = true; } - ); + ); }); } else if (!user.duplicate || (user.duplicateAction == $scope.duplicateActions[2])) { diff --git a/openslides/users/static/templates/users/user-list.html b/openslides/users/static/templates/users/user-list.html index 6ce7a9ca7..801f8994f 100644 --- a/openslides/users/static/templates/users/user-list.html +++ b/openslides/users/static/templates/users/user-list.html @@ -21,7 +21,8 @@