From d1f0b69d359aa10a6d004c515ea437b58a6e360d Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 12 May 2017 12:02:01 +0200 Subject: [PATCH] Fixing PDF filenames on zip export if no identifier is given --- openslides/motions/static/js/motions/pdf.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/openslides/motions/static/js/motions/pdf.js b/openslides/motions/static/js/motions/pdf.js index 528698f4e..750067aa5 100644 --- a/openslides/motions/static/js/motions/pdf.js +++ b/openslides/motions/static/js/motions/pdf.js @@ -723,9 +723,23 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf']) var self = this; var pdfs = {}; + var usedFilenames = []; var pdfPromises = _.map(motions, function (motion) { var identifier = motion.identifier ? '-' + motion.identifier : ''; - var filename = gettextCatalog.getString('Motion') + identifier + '.pdf'; + var filename = gettextCatalog.getString('Motion') + identifier; + + // If the filename is already in use, try to append a number to it (like '(2)') + if (_.includes(usedFilenames, filename)) { + var i = 1; + var filenameWithNumber = filename; + while(_.includes(usedFilenames, filenameWithNumber)) { + filenameWithNumber = filename + ' (' + i + ')'; + i++; + } + filename = filenameWithNumber; + } + usedFilenames.push(filename); + filename += '.pdf'; return $q(function (resolve, reject) { // get documentProvider for every motion.