Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit 07c038a

Browse files
add email domain to student index
1 parent dac8375 commit 07c038a

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

sw-admin/templates/addpoll.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h3 class="mb-5">Dodawanie nowego głosowania</h3>
4545
<br />
4646

4747
Głosujacy (adresy email w nowych liniach): <br/>
48-
<textarea class="form-control" id="pollRecipients" placeholder="1@student.pwr.edu.pl&#10;2@student.pwr.edu.pl&#10;..." rows=10></textarea>
48+
<textarea class="form-control" id="pollRecipients" placeholder="1@student.pwr.edu.pl&#10;2@student.pwr.edu.pl&#10;123456&#10;..." rows=10></textarea>
4949
<br /> <br />
5050
<div class="d-flex justify-content-left align-items-center">
5151
Data zakończenia głosowania:
@@ -110,12 +110,12 @@ <h3 class="mb-5">Dodawanie nowego głosowania</h3>
110110

111111
<script>
112112
function deleteRow(el) {
113-
var row = el.parentNode.parentNode;
113+
const row = el.parentNode.parentNode;
114114
document.getElementById('pollOptionsTBody').removeChild(row);
115115
}
116116
function addRow(el) {
117-
var row = el.parentNode.parentNode;
118-
var tr = document.createElement('tr');
117+
const row = el.parentNode.parentNode;
118+
const tr = document.createElement('tr');
119119
tr.innerHTML = '<td><input class="form-control" type="text" placeholder="Jan Kowalski"></td>';
120120
tr.innerHTML += '<td><input class="form-control" type="text" placeholder="Wydział Architektury"></td>';
121121
tr.innerHTML += '<td><button class="btn btn-danger" onclick="deleteRow(this)"><i class="fas fa-trash-alt"></i></button></td>';
@@ -125,7 +125,7 @@ <h3 class="mb-5">Dodawanie nowego głosowania</h3>
125125
return document.getElementById(elName).value;
126126
}
127127
function sendForm(data) {
128-
let form = document.createElement('form');
128+
const form = document.createElement('form');
129129
form.method = "POST";
130130
form.action = "";
131131
form.style.display = 'none';
@@ -140,17 +140,24 @@ <h3 class="mb-5">Dodawanie nowego głosowania</h3>
140140
form.submit();
141141
}
142142
function send() {
143-
let options = Array.from(document.getElementById('pollOptionsTBody').rows)
143+
const options = Array.from(document.getElementById('pollOptionsTBody').rows)
144144
.filter(row => row.childElementCount != 1) // filter out the last row with the add button
145145
.map(row => ({
146146
name: row.children[0].getElementsByTagName('input')[0].value,
147147
description: row.children[1].getElementsByTagName('input')[0].value,
148148
}));
149-
let data = {
149+
const createPollRecipient = (recipient) => {
150+
recipient = recipient.trim();
151+
if (recipient.split('@').length === 1 && /^\d+$/.test(recipient.split('@')[0])) {
152+
return recipient.concat('@student.pwr.edu.pl');
153+
}
154+
return recipient;
155+
}
156+
const data = {
150157
name: val('pollName'),
151158
options: JSON.stringify(options),
152159
choiceType: 'multiple-choice',
153-
recipients: JSON.stringify(pollRecipients.value.split('\n').filter(email => email.length != 0).map(email => email.trim())),
160+
recipients: JSON.stringify(pollRecipients.value.split('\n').filter(email => email.length != 0).map(recipient => createPollRecipient(recipient))),
154161
closesOnDate: val('pollClosesOnDate') + ' ' + val('pollClosesOnTime'),
155162
visibility: 'private',
156163
mailTemplate: val('pollMailTemplate'),

sw-admin/templates/editpoll.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h3 class="mb-5">{% block header %}Edycja głosowania "{{name}}"{% endblock %}</
5555
<br /> <br />
5656

5757
Głosujacy (adresy email w nowych liniach): <br/>
58-
<textarea class="form-control" id="pollRecipients" placeholder="1@student.pwr.edu.pl&#10;2@student.pwr.edu.pl&#10;..." rows=10 {{should_disable}}>{{ "\n".join(possible_recipients) }}</textarea>
58+
<textarea class="form-control" id="pollRecipients" placeholder="1@student.pwr.edu.pl&#10;2@student.pwr.edu.pl&#10;123456&#10;..." rows=10 {{should_disable}}>{{ "\n".join(possible_recipients) }}</textarea>
5959
<br /> <br />
6060
<div class="d-flex justify-content-left align-items-center">
6161
Data zakończenia głosowania:
@@ -81,12 +81,12 @@ <h3 class="mb-5">{% block header %}Edycja głosowania "{{name}}"{% endblock %}</
8181

8282
<script>
8383
function deleteRow(el) {
84-
var row = el.parentNode.parentNode;
84+
const row = el.parentNode.parentNode;
8585
document.getElementById('pollOptionsTBody').removeChild(row);
8686
}
8787
function addRow(el) {
88-
var row = el.parentNode.parentNode;
89-
var tr = document.createElement('tr');
88+
const row = el.parentNode.parentNode;
89+
const tr = document.createElement('tr');
9090
tr.innerHTML = '<td><input class="form-control" type="text" placeholder="Jan Kowalski"></td>';
9191
tr.innerHTML += '<td><input class="form-control" type="text" placeholder="Wydział Architektury"></td>';
9292
tr.innerHTML += '<td><button class="btn btn-danger" onclick="deleteRow(this)"><i class="fas fa-trash-alt"></i></button></td>';
@@ -96,7 +96,7 @@ <h3 class="mb-5">{% block header %}Edycja głosowania "{{name}}"{% endblock %}</
9696
return document.getElementById(elName).value;
9797
}
9898
function sendForm(data) {
99-
let form = document.createElement('form');
99+
const form = document.createElement('form');
100100
form.method = "POST";
101101
form.action = "{% block formactionpath %}?id={{poll_id}}{% endblock %}";
102102
form.style.display = 'none';
@@ -111,17 +111,24 @@ <h3 class="mb-5">{% block header %}Edycja głosowania "{{name}}"{% endblock %}</
111111
form.submit();
112112
}
113113
function send() {
114-
let options = Array.from(document.getElementById('pollOptionsTBody').rows)
114+
const options = Array.from(document.getElementById('pollOptionsTBody').rows)
115115
.filter(row => row.childElementCount != 1) // filter out the last row with the add button
116116
.map(row => ({
117117
name: row.children[0].getElementsByTagName('input')[0].value,
118118
description: row.children[1].getElementsByTagName('input')[0].value,
119119
}));
120-
let data = {
120+
const createPollRecipient = (recipient) => {
121+
recipient = recipient.trim();
122+
if (recipient.split('@').length === 1 && /^\d+$/.test(recipient.split('@')[0])) {
123+
return recipient.concat('@student.pwr.edu.pl');
124+
}
125+
return recipient;
126+
}
127+
const data = {
121128
name: val('pollName'),
122129
options: JSON.stringify(options),
123130
choiceType: 'multiple-choice',
124-
recipients: JSON.stringify(pollRecipients.value.split('\n').filter(email => email.length != 0).map(email => email.trim())),
131+
recipients: JSON.stringify(pollRecipients.value.split('\n').filter(email => email.length != 0).map(recipient => createPollRecipient(recipient))),
125132
closesOnDate: val('pollClosesOnDate') + ' ' + val('pollClosesOnTime'),
126133
visibility: 'private',
127134
mailTemplate: val('pollMailTemplate'),

0 commit comments

Comments
 (0)