From ee28811d1e78a2ce52af0e1cbc422fda998ac1e4 Mon Sep 17 00:00:00 2001 From: dawidos234 Date: Mon, 18 Jul 2022 18:41:13 +0200 Subject: [PATCH] ISSUE-5 automatically add domain to recipient --- sw-admin/templates/addpoll.html | 19 +++++++++++++++++-- sw-admin/templates/editpoll.html | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/sw-admin/templates/addpoll.html b/sw-admin/templates/addpoll.html index e700e41..8855efc 100644 --- a/sw-admin/templates/addpoll.html +++ b/sw-admin/templates/addpoll.html @@ -45,7 +45,7 @@

Dodawanie nowego głosowania


Głosujacy (adresy email w nowych liniach):
- +

Data zakończenia głosowania: @@ -139,6 +139,18 @@

Dodawanie nowego głosowania

document.body.appendChild(form); form.submit(); } + + const createPollRecipient = (recipient) => { + recipient = recipient.trim(); + if (recipient.split('@').length === 2) { + if (/^\d+$/.test(recipient.split('@')[0])) { + return recipient; + } + } else if (recipient.split('@').length === 1 && /^\d+$/.test(recipient.split('@')[0])) { + return recipient + '@student.pwr.edu.pl'; + } + } + function send() { let options = Array.from(document.getElementById('pollOptionsTBody').rows) .filter(row => row.childElementCount != 1) // filter out the last row with the add button @@ -150,7 +162,10 @@

Dodawanie nowego głosowania

name: val('pollName'), options: JSON.stringify(options), choiceType: 'multiple-choice', - recipients: JSON.stringify(pollRecipients.value.split('\n').filter(email => email.length != 0).map(email => email.trim())), + recipients: JSON.stringify( + pollRecipients.value.split('\n') + .map(email => createPollRecipient(email)).filter(x => x) + ), closesOnDate: val('pollClosesOnDate') + ' ' + val('pollClosesOnTime'), visibility: 'private', mailTemplate: val('pollMailTemplate'), diff --git a/sw-admin/templates/editpoll.html b/sw-admin/templates/editpoll.html index c58e61c..07dbd84 100644 --- a/sw-admin/templates/editpoll.html +++ b/sw-admin/templates/editpoll.html @@ -55,7 +55,7 @@

{% block header %}Edycja głosowania "{{name}}"{% endblock %}
Głosujacy (adresy email w nowych liniach):
- +

Data zakończenia głosowania: @@ -110,6 +110,18 @@

{% block header %}Edycja głosowania "{{name}}"{% endblock %} { + recipient = recipient.trim(); + if (recipient.split('@').length === 2) { + if (/^\d+$/.test(recipient.split('@')[0])) { + return recipient; + } + } else if (recipient.split('@').length === 1 && /^\d+$/.test(recipient.split('@')[0])) { + return recipient + '@student.pwr.edu.pl'; + } + } + function send() { let options = Array.from(document.getElementById('pollOptionsTBody').rows) .filter(row => row.childElementCount != 1) // filter out the last row with the add button @@ -121,7 +133,10 @@

{% block header %}Edycja głosowania "{{name}}"{% endblock %} email.length != 0).map(email => email.trim())), + recipients: JSON.stringify( + pollRecipients.value.split('\n') + .map(email => createPollRecipient(email)).filter(x => x) + ), closesOnDate: val('pollClosesOnDate') + ' ' + val('pollClosesOnTime'), visibility: 'private', mailTemplate: val('pollMailTemplate'),