-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.html
282 lines (255 loc) · 10.8 KB
/
index.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
{% extends "wagtailusers/users/index.html" %}
{% load wagtailadmin_tags i18n %}
{% block content %}
{% trans "Users" as users_str %}
{% url "wagtailusers_users:add" as add_link %}
<header class=" hasform">
<div class="row">
<div class="left">
<div class="col">
<h1><svg class="icon icon-user icon" aria-hidden="true"><use href="#icon-user"></use></svg>
Users
</h1>
</div>
<form class="col search-form" action="/admin/users/" method="get" novalidate="" role="search">
<ul class="fields">
<li class="required">
<div class="field char_field text_input field-small iconfield" data-contentpath="q">
<label for="id_q">Search term:</label>
<div class="field-content">
<div class="input">
<svg class="icon icon-search icon" aria-hidden="true"><use href="#icon-search"></use></svg>
<input type="text" name="q" placeholder="Search users" required="" id="id_q">
<span></span>
</div>
</div>
</div>
</li>
<li class="visuallyhidden"><input disabled="" type="submit" aria-hidden="true"></li>
<li class="submit visuallyhidden"><input type="submit" value="Search" class="button"></li>
</ul>
</form>
</div>
<div class="right">
<div class="actionbutton action-buttons">
<!-- <button id="invite-admin-button" class="button button--icon" style="margin-left: 10px;">
{% icon name="plus" wrapped=1 %} Invite Admin User
</button> -->
<a href="/admin/users/add/" class="button bicolor button--icon">
<span class="icon-wrapper"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></span>
Add a user
</a>
</div>
</div>
</div>
</header>
<div id="invite-admin-modal" class="modal">
<div class="modal-content">
<div>
<span class="close-button" id="close-modal">×</span>
<h2>Invite Admin User</h2>
</div>
<hr>
<form id="invite-admin-form">
<div class="input-group">
<div class="input-field">
<input type="text" id="first_name" name="first_name" placeholder="First Name">
<span class="error-message" id="first_name_error" style="color: red; display: none;"></span>
</div>
<div class="input-field">
<input type="text" id="last_name" name="last_name" placeholder="Last Name">
<span class="error-message" id="last_name_error" style="color: red; display: none;"></span>
</div>
</div>
<div class="input-field">
<input type="text" id="email" name="email" placeholder="Email Address" title="Please enter a valid email address">
<span class="error-message" id="email_error" style="color: red; display: none;"></span>
</div>
<div class="form-actions">
<button type="submit" class="button button--icon" style="border-radius: 5px;">Send Invite</button>
</div>
</form>
</div>
</div>
<style>
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% 36%;
padding: 20px;
border: 1px solid #888;
width: 25%;
border-radius: 10px;
}
.close-button {
color: black;
float: right;
font-size: 28px;
font-weight: bold;
}
.close-button:hover,
.close-button:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.error-message {
display: block;
color: red;
}
hr{
border-color: black;
}
.input-group {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
.input-field {
flex: 1;
}
.input-field input {
border: 1px solid #888;
width: 100%;
padding: 10px;
font-weight: 400;
border-radius: 5px;
}
input.invalid {
border: 1px solid red;
}
.form-actions {
display: flex;
justify-content: flex-end;
margin-top: 25px;
}
</style>
{% endblock %}
{% block extra_js %}
{{ block.super }}
<script>
document.addEventListener('DOMContentLoaded', function() {
const inviteAdminButton = document.getElementById('invite-admin-button');
const modal = document.getElementById('invite-admin-modal');
const closeButton = document.getElementById('close-modal');
const form = document.getElementById('invite-admin-form');
const inputs = form.querySelectorAll('input');
const body = document.querySelector('body');
inviteAdminButton.onclick = function() {
modal.style.display = 'block';
form.reset();
resetErrorMessages();
};
closeButton.onclick = function() {
modal.style.display = 'none';
};
form.onsubmit = function(event) {
event.preventDefault();
resetErrorMessages();
const firstName = document.getElementById('first_name').value;
const lastName = document.getElementById('last_name').value;
const email = document.getElementById('email').value;
let isValid = true;
if (firstName.trim() === "") {
showError('first_name', "First Name is required.");
isValid = false;
}
if (lastName.trim() === "") {
showError('last_name', "Last Name is required.");
isValid = false;
}
if (!validateEmail(email)) {
showError('email', "Please enter a valid email address.");
isValid = false;
}
if (isValid) {
const formData = new FormData(form);
fetch("{% url 'invite_admin_user' %}", {
method: 'POST',
body: formData,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
modal.style.display = 'none';
form.reset();
displaySuccessMessage("Invite sent successfully!");
setTimeout(() => {
modal.style.display = 'none';
}, 1000);
} else {
for (const [key, value] of Object.entries(data.errors)) {
showError(key, value);
}
}
})
.catch(error => console.error('Error:', error));
}
};
function validateEmail(email) {
const re = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
return re.test(String(email).toLowerCase());
}
function resetErrorMessages() {
const errorMessages = document.querySelectorAll('.error-message');
errorMessages.forEach(function(errorMessage) {
errorMessage.textContent = '';
errorMessage.style.display = 'none';
});
const invalidInputs = document.querySelectorAll('input.invalid');
invalidInputs.forEach(function(input) {
input.classList.remove('invalid');
});
}
function showError(inputId, message) {
const errorElement = document.getElementById(inputId + '_error');
errorElement.textContent = message;
errorElement.style.display = 'block';
document.getElementById(inputId).classList.add('invalid');
}
function displaySuccessMessage(message){
const successMessage = document.createElement('div');
successMessage.textContent = message;
successMessage.style.cssText = `
position: fixed;
bottom: 10px;
right: 10px;
background-color: #134f5c;
color: white;
padding: 15px 20px;
border-radius: 5px;
z-index: 1001;
font-size: 14px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
font-weight: bold;
`;
body.appendChild(successMessage);
setTimeout(() => {
successMessage.remove();
}, 1000);
}
inputs.forEach(input => {
input.addEventListener('input', function() {
const errorMessage = document.getElementById(input.id + '_error');
if (errorMessage) {
errorMessage.style.display = 'none';
}
input.classList.remove('invalid');
});
});
});
</script>
{% endblock %}