Fixing PDF filenames on zip export if no identifier is given

This commit is contained in:
FinnStutzenstein 2017-05-12 12:02:01 +02:00
parent 2833341867
commit d1f0b69d35

View File

@ -723,9 +723,23 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
var self = this; var self = this;
var pdfs = {}; var pdfs = {};
var usedFilenames = [];
var pdfPromises = _.map(motions, function (motion) { var pdfPromises = _.map(motions, function (motion) {
var identifier = motion.identifier ? '-' + motion.identifier : ''; 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) { return $q(function (resolve, reject) {
// get documentProvider for every motion. // get documentProvider for every motion.