From c0192e9e003639a51948314c6cfd4d68f4192cb0 Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Mon, 18 May 2026 10:23:41 +0200 Subject: [PATCH] adjusted flatTable index to paabgabe_id since projektarbeit_id is not unique per row there; fixed splitMailHelpers call in Mitarbeiter page; emailHelper changes so it actually works with bcc aswell; --- .../Cis/Abgabetool/AbgabetoolAssistenz.js | 2 +- .../Cis/Abgabetool/AbgabetoolMitarbeiter.js | 2 +- public/js/helpers/EmailHelpers.js | 72 +++++++++++-------- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js b/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js index 5fb9c8db6..2c45c0f18 100644 --- a/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js +++ b/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js @@ -319,7 +319,7 @@ export const AbgabetoolAssistenz = { abgabeTableOptionsFlat: { minHeight: 250, height: 700, - index: 'projektarbeit_id', + index: 'paabgabe_id', layout: 'fitColumns', placeholder: Vue.computed(() => this.$capitalize(this.$p.t('global/noDataAvailable'))), selectable: true, diff --git a/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js b/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js index fe32d4982..9d8db2d8f 100644 --- a/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js +++ b/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js @@ -531,7 +531,7 @@ export const AbgabetoolMitarbeiter = { }) const uniqueRecipients = [...new Set(recipientList)]; const subject = ""; // empty subject line - splitMailsHelper(uniqueRecipients, param.originalEvent, subject, this.$fhcAlert, this.$p) + splitMailsHelper(uniqueRecipients, param.originalEvent, subject, null, this.$fhcAlert, this.$p) }, getQGateStatusList() { return [ diff --git a/public/js/helpers/EmailHelpers.js b/public/js/helpers/EmailHelpers.js index 207f4d6c2..ce2115c04 100644 --- a/public/js/helpers/EmailHelpers.js +++ b/public/js/helpers/EmailHelpers.js @@ -1,50 +1,66 @@ export async function splitMailsHelper(mails, event, subject, body, alertPluginRef, phrasenPluginRef) { - await phrasenPluginRef.loadCategory('ui') - + await phrasenPluginRef.loadCategory('ui'); + let splititem = ","; let maillist = mails.join(splititem); - let mailto = ""; - let encodedBody = body && typeof body === 'string' ? encodeURIComponent(body) : null; - const subjectlength = subject && typeof subject === 'string' ? subject.length + 9 : 0; - let bodylength = encodedBody ? encodedBody.length + 6 : 0; - let overhead = subjectlength + bodylength; + let useBcc = event?.ctrlKey || event?.metaKey; - if (overhead > 2024) - { + // build query parameters using URLSearchParams to get encoding + const urlParams = new URLSearchParams(); + if (subject && typeof subject === 'string') { + urlParams.append('subject', subject); + } + if (body && typeof body === 'string') { + urlParams.append('body', body); + } + + // initial overhead: "mailto:?bcc=" -> 12 chars, "mailto:" -> 7 chars + const baseOverhead = useBcc ? 12 : 7; + let queryString = urlParams.toString(); + let overhead = baseOverhead + (queryString ? 1 + queryString.length : 0); // +1 accounts for '?' or '&' + + // calculate overhead with body to exceed the limit + if (overhead > 2024) { await alertPluginRef.alertWarning(phrasenPluginRef.t('ui', 'bodyZuLang')); - encodedBody = null; - overhead = subjectlength; + urlParams.delete('body'); + queryString = urlParams.toString(); + overhead = baseOverhead + (queryString ? 1 + queryString.length : 0); } let firstrun = true; - let useBcc = event?.ctrlKey || event?.metaKey; - while (maillist.length > 0) - { - if (maillist.length + overhead > 2024) - { + while (maillist.length > 0) { + let mailto = ""; + if (maillist.length + overhead > 2024) { let splitposition = maillist.lastIndexOf(splititem, 2024 - overhead); + + // Fallback guard: if a single email address is somehow longer than the remaining space + if (splitposition === -1) { + splitposition = maillist.indexOf(splititem); + if (splitposition === -1) splitposition = maillist.length; + } + mailto = maillist.substring(0, splitposition); maillist = maillist.substring(splitposition + 1); - } - else - { + } else { mailto = maillist; maillist = ""; } + // construct the clean mailLink let mailLink = useBcc ? `mailto:?bcc=${mailto}` : `mailto:${mailto}`; - if (subject && typeof subject === 'string') mailLink += `?subject=${subject}`; - if (encodedBody) mailLink += `&body=${encodedBody}`; - if (firstrun) - { + if (queryString) { + // If using BCC, the string already has a '?', so append with '&'. Otherwise, start with '?' + mailLink += useBcc ? `&${queryString}` : `?${queryString}`; + } + + if (firstrun) { window.location.href = mailLink; firstrun = false; - } - else - { - if (await alertPluginRef.confirm({message: phrasenPluginRef.t('ui', 'weitereEMail')}) === true) - { + } else { + if (await alertPluginRef.confirm({message: phrasenPluginRef.t('ui', 'weitereEMail')}) === true) { window.location.href = mailLink; + } else { + break; // Stop processing further batches if the user cancels } } }