-
Notifications
You must be signed in to change notification settings - Fork 26
/
edit-jc.html
109 lines (100 loc) · 4.32 KB
/
edit-jc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
layout: default
---
{% include keys.html %}
<link rel="stylesheet" type="text/css" href="/assets/css/join-form.css"/>
<script type="text/javascript" src="/assets/js/join-form.js"></script>
<article>
<section id="edit">
<h1>Edit a journal club</h1>
<p>To approve the editing of your journal club, we'll generate a one-time link for you to follow and send that link to your email address. Please note that only email addresses already listed in your journal club are allowed to make edits.</p>
<p>If you run into problems while making edits, or need something the automated form cannot provide, please email us.</p>
<div id="EditForm">
<div>
<label for="jcid">Journal club:</label>
<select id="jcid" name="jcid" onchange="updateEmailOptions()">
{% for jc in site.journal-clubs %}
<option value="{{jc.jcid}}" data-emails="{{jc.contact}}, {{jc.additional-contact | join: ', '}}">{{jc.title}}</option>
{% endfor %}
</select>
</div>
<div>
<label for="email">Email:</label>
<select id="email" name="email"></select>
</div>
<div>
<label for="message">Commit message:</label>
<textarea id="message" name="message" placeholder="Here you can (optionally) describe what it is you're trying to do. This will appear in the GitHub change logs and can help us see at a glance what kind of changes are being made to a journal club. Example: 'Changed lead organiser.'"></textarea>
</div>
<div>
<button onclick="getToken()">Get edit token</button>
</div>
</div>
</section>
</article>
<section id="LoadingModal">
<div>
<h2>Edit journal club</h2>
<div id="CheckToken">
<i class="fa-hourglass fas fa-spin"></i>
<p>Creating access token</p>
</div>
<div id="TokenOkay">
<p>A link has been emailed to the requested address.</p>
<p>Please close this page and open the link sent to you by email.</p>
<p>If you have not gotten an email, please check your spam folder.</p>
</div>
<div id="RejectToken">
<i class="fas fa-exclamation-triangle"></i>
<p>We were unable to create an access token.</p>
<p>You may have too many recent unused tokens for your journal club, or there may be a problem with our services.</p>
<p>Should this problem persist, please contact us via email.</p>
</div>
</div>
</section>
<script>
/**
* Generate a token for authorising edits and send to the requested email
*/
async function getToken() {
// Update visuals
const modal = document.getElementById('LoadingModal');
modal.classList.add('token-check');
const jcid = document.getElementById('jcid').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
await fetch('/.netlify/functions/edit-jc_create-token', {
method: 'POST',
body: JSON.stringify({jcid, email, message})
})
.then(r => {
if(r.status !== 200)
throw new Error(`Token generation failed: ${r.statusText} (${r.status})`)
})
.then(() => modal.classList.add('token-okay'))
.catch(e => modal.classList.add('token-reject'));
}
/**
* Update email select options to match jc option
* @param e {Event}
*/
function updateEmailOptions() {
const jcs = document.getElementById('jcid');
const jc = jcs.querySelectorAll('option')[jcs.selectedIndex];
const opts = document.getElementById('email');
// remove previous options
opts
.querySelectorAll('option')
.forEach(o => o.parentElement.removeChild(o));
const emails = jc.dataset.emails.split(',');
emails
.filter(x => !/^[ ,]*$/.test(x))
.forEach(x => {
const o = document.createElement('option');
o.value = x;
o.innerHTML = x;
opts.appendChild(o);
})
}
updateEmailOptions();
</script>