extracted email split method from stv/kontakt component to helperfile; adjusted that method to take subject param & make phrasen/alert call via parameter reference;

This commit is contained in:
Johann Hoffmann
2026-02-12 17:38:00 +01:00
parent 5c1e967d5e
commit 043b1bcf11
3 changed files with 56 additions and 57 deletions
@@ -7,6 +7,7 @@ import ApiAbgabe from '../../../api/factory/abgabe.js'
import ApiStudiensemester from '../../../api/factory/studiensemester.js';
import AbgabeterminStatusLegende from "./StatusLegende.js";
import FhcOverlay from "../../Overlay/FhcOverlay.js";
import { splitMailsHelper } from "../../../helpers/EmailHelpers.js"
// spoofed date testing
// const todayISO = '2025-08-08'
@@ -226,18 +227,17 @@ export const AbgabetoolAssistenz = {
]};
},
methods: {
sammelMailStudent() {
sammelMailStudent(param) {
const emails = this.selectedData
.map(row => `${row.student_uid}@${this.domain}`)
.join(',');
const uniqueRecipients = [...new Set(emails)];
const subject = this.$p.t('abgabetool/c4sammelmailStudentBetreff', [this.selectedStudiengangOption?.bezeichnung]);
const href = `mailto:${emails}?subject=${subject}`;
window.location.href = href
splitMailsHelper(uniqueRecipients, param.originalEvent, subject, this.$fhcAlert, this.$p)
},
sammelMailBetreuer() {
sammelMailBetreuer(param) {
const recipientList = [];
this.selectedData.forEach(row => {
if (row.betreuer_mail) recipientList.push(row.betreuer_mail);
@@ -246,11 +246,8 @@ export const AbgabetoolAssistenz = {
// actually not necessary for email clients but looks better for assistenz if we avoid duplicates here
const uniqueRecipients = [...new Set(recipientList)];
const subject = this.$p.t('abgabetool/c4sammelmailBetreuerBetreff', [this.selectedStudiengangOption?.bezeichnung]);
const href = `mailto:${uniqueRecipients.join(',')}?subject=${encodeURIComponent(subject)}`;
window.location.href = href;
splitMailsHelper(uniqueRecipients, param.originalEvent, subject, this.$fhcAlert, this.$p)
},
selectHandler(e, cell) {
const row = cell.getRow();
@@ -1,3 +1,4 @@
import { splitMailsHelper } from "../../../../helpers/EmailHelpers.js"
export default {
name: "Kontaktieren",
computed: {
@@ -22,60 +23,16 @@ export default {
},
methods: {
async splitMails(mails, event) {
let splititem = ",";
let maillist = mails.join(splititem);
let mailto = "";
if (maillist.length > 2024)
{
if (await this.$fhcAlert.confirm({message: this.$p.t('stv', 'zuvieleEMails') }) === false)
return;
}
let firstrun = true;
let useBcc = event?.ctrlKey || event?.metaKey;
while (maillist.length > 0)
{
if (maillist.length > 2024)
{
let splitposition = maillist.lastIndexOf(splititem, 1900);
mailto = maillist.substring(0, splitposition);
maillist = maillist.substring(splitposition + 1);
}
else
{
mailto = maillist;
maillist = "";
}
let mailLink = useBcc ? `mailto:?bcc=${mailto}` : `mailto:${mailto}`;
if (firstrun)
{
window.location.href = mailLink;
firstrun = false;
}
else
{
if (await this.$fhcAlert.confirm({message: this.$p.t('stv', 'weitereEMail')}) === true)
{
window.location.href = mailLink;
}
}
}
},
internMail(event) {
if (this.internMails.length)
{
this.splitMails(this.internMails, event);
splitMailsHelper(this.privateMails, event, null, this.$fhcAlert, this.$p)
}
},
privateMail(event) {
if (this.privateMails.length)
{
this.splitMails(this.privateMails, event);
splitMailsHelper(this.privateMails, event, null, this.$fhcAlert, this.$p)
}
}
},
+45
View File
@@ -0,0 +1,45 @@
export async function splitMailsHelper(mails, event, subject, alertPluginRef, phrasenPluginRef) {
let splititem = ",";
let maillist = mails.join(splititem);
let mailto = "";
// take subject line length + '?subject=' length into account
const subjectlength = subject && typeof subject === 'string' ? subject.length + 9 : 0
if (maillist.length > 2024)
{
if (await alertPluginRef.confirm({message: phrasenPluginRef.t('stv', 'zuvieleEMails') }) === false)
return;
}
let firstrun = true;
let useBcc = event?.ctrlKey || event?.metaKey;
while (maillist.length > 0)
{
if (maillist.length + subjectlength > 2024)
{
let splitposition = maillist.lastIndexOf(splititem, 1900);
mailto = maillist.substring(0, splitposition);
maillist = maillist.substring(splitposition + 1);
}
else
{
mailto = maillist;
maillist = "";
}
let mailLink = useBcc ? `mailto:?bcc=${mailto}` : `mailto:${mailto}`;
if(subject && typeof subject === 'string') mailLink += `?subject=${subject}`
if (firstrun)
{
window.location.href = mailLink;
firstrun = false;
}
else
{
if (await alertPluginRef.confirm({message: phrasenPluginRef.t('stv', 'weitereEMail')}) === true)
{
window.location.href = mailLink;
}
}
}
}