-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSidebarPrepSheets.html
More file actions
300 lines (271 loc) · 13.6 KB
/
SidebarPrepSheets.html
File metadata and controls
300 lines (271 loc) · 13.6 KB
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
M.updateTextFields();
var elems = document.querySelectorAll('select');
M.FormSelect.init(elems);
// Toggle visibility of alt password options
$('#altPass').change(function() {
if ($(this).is(':checked')) {
$('#altOptions').show();
} else {
$('#altOptions').hide();
}
});
// Toggle visibility of random length input
$('#passType').change(function() {
if ($(this).val() === 'random') {
$('#randomLengthBox').show();
} else {
$('#randomLengthBox').hide();
}
});
});
</script>
<style>
.container { width: 95%; padding: 5px; }
.spogou-input {
background-color: #fafafa !important;
border: 1px solid #e0e0e0 !important;
border-radius: 2px !important;
padding: 0 30px 0 10px !important;
height: 3rem !important;
width: 100% !important;
box-sizing: border-box !important;
text-align: left !important;
margin-bottom: 8px !important;
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2) !important;
}
.clear-icon {
position: absolute;
right: 35px;
cursor: pointer;
color: #9e9e9e;
font-size: 18px;
display: none;
}
.info-box { font-size: 0.9rem; padding: 10px; margin-bottom: 15px; }
.section-header { margin-top: 20px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
</style>
<div class="container">
<h6><b>Step 1: Identify Target Users</b></h6>
<div class="card-panel blue lighten-4 info-box">
Enter the teacher's email and select a Group or Classroom to fetch students from.
</div>
<div class="row">
<div class="input-field col s12">
<!-- Teacher Email -->
<div style="display: flex; align-items: center; position: relative;">
<input placeholder="Teacher Email (Requester)" type="text" id="teacheremail" list="teachers-list" class="spogou-input" oninput="validate()">
<i id="teacher-clear" class="material-icons clear-icon">close</i>
<i id="teacher-validation-icon" class="material-icons" style="margin-left: 10px; display: none;"></i>
</div>
<datalist id="teachers-list"></datalist>
<!-- Group Email -->
<div style="display: flex; align-items: center; position: relative;">
<input placeholder="Target Group Email" type="text" id="groupemail" list="groups-list" class="spogou-input" oninput="validate()" disabled>
<i id="group-clear" class="material-icons clear-icon">close</i>
<i id="group-validation-icon" class="material-icons" style="margin-left: 10px; display: none;"></i>
</div>
<datalist id="groups-list"></datalist>
<!-- Classroom Selection -->
<div style="display: flex; align-items: center; position: relative;">
<input placeholder="OR Select Classroom" type="text" id="classroom" list="classroom-list" class="spogou-input" oninput="validate()" disabled>
<i id="classroom-clear" class="material-icons clear-icon">close</i>
<i id="classroom-validation-icon" class="material-icons" style="margin-left: 10px; display: none;"></i>
</div>
<datalist id="classroom-list"></datalist>
<div id="classroom-help" style="font-size: 0.75rem; color: #757575; display: none; margin-top: -5px; margin-bottom: 10px;">
Don't see the classroom? Use the <b>Classroom Visitor</b> feature to join it first.
</div>
</div>
<div class="input-field col s12 section-header">
<h6><b>Step 2: Password Options</b></h6>
</div>
<div class="input-field col s12">
<select id="changePass">
<option value="FALSE">FALSE</option>
<option value="TRUE">TRUE</option>
</select>
<label>Force password reset on first login?</label>
</div>
<div class="col s12">
<p>
<label>
<input type="checkbox" id="altPass" />
<span>Use alternative password generation</span>
</label>
</p>
</div>
<div id="altOptions" style="display: none;">
<div class="input-field col s12">
<select id="passType">
<option value="simple">Simple (Firstname + Numbers)</option>
<option value="random">Random Characters</option>
<option value="word">Word-based</option>
</select>
<label>Password Type</label>
</div>
<div id="randomLengthBox" class="input-field col s12" style="display: none;">
<input id="passLength" type="number" value="12" min="8" max="32">
<label for="passLength">Password Length</label>
</div>
</div>
<div class="col s12" style="text-align: right; margin-top: 20px;">
<button type="button" class="btn waves-effect waves-light blue" id="btnNext" disabled>NEXT</button>
</div>
</div>
</div>
<script>
var field1 = document.getElementById("groupemail");
var field2 = document.getElementById("teacheremail");
var field3 = document.getElementById("classroom");
var buttonNext = document.getElementById("btnNext");
var classroomHelp = document.getElementById("classroom-help");
var searchCache = {};
var cachedGroups = [];
var cachedTeachers = [];
var cachedClassrooms = [];
var lastFetchedTeacher = "";
function validate(){
var tValid = isVerified('teacher-validation-icon');
var gValid = isVerified('group-validation-icon');
var cValid = isVerified('classroom-validation-icon');
buttonNext.disabled = !(tValid && (gValid || cValid));
}
function isVerified(id) {
var icon = document.getElementById(id);
if (!icon || icon.style.display === 'none') return false;
return icon.innerText === 'check_circle' || icon.innerText === 'check';
}
function updateValidationUI(query, iconId, results, clearId) {
var icon = document.getElementById(iconId);
var clear = document.getElementById(clearId);
clear.style.display = query.length > 0 ? 'block' : 'none';
if (query.length < 3) { icon.style.display = 'none'; validate(); return; }
var exact = results.some(function(item) {
return (item.email && item.email.toLowerCase() === query.toLowerCase()) ||
(item.name && item.name.toLowerCase() === query.toLowerCase());
});
icon.style.display = 'inline-block';
if (exact) {
icon.innerText = 'check_circle'; icon.style.color = 'green';
} else if (iconId === 'teacher-validation-icon' && /\S+@\S+\.\S+/.test(query)) {
icon.innerText = 'check'; icon.style.color = 'blue';
} else {
icon.innerText = 'error'; icon.style.color = 'orange';
}
if (iconId === 'teacher-validation-icon') handleTeacherState(query);
validate();
}
function handleTeacherState(email) {
var verified = isVerified('teacher-validation-icon');
field1.disabled = !verified;
if (verified) {
if (email !== lastFetchedTeacher) {
lastFetchedTeacher = email;
fetchClassrooms(email);
}
} else {
field1.value = ''; field3.value = ''; field3.disabled = true;
document.getElementById('group-validation-icon').style.display = 'none';
document.getElementById('classroom-validation-icon').style.display = 'none';
classroomHelp.style.display = 'none';
}
}
function fetchClassrooms(email) {
field3.disabled = true;
field3.value = '';
classroomHelp.style.display = 'none';
google.script.run.withSuccessHandler(function(rooms) {
cachedClassrooms = rooms;
renderResults('classroom-list', rooms);
field3.disabled = false;
if (rooms.length === 0) {
field3.placeholder = "No classrooms found";
classroomHelp.style.display = 'block';
} else {
field3.placeholder = "Select Classroom (" + rooms.length + ")";
}
validate();
}).getClassrooms(email);
}
function setupAutocomplete(input, listId, iconId, serverFunc, resultsRef, clearId) {
var timeout;
document.getElementById(clearId).addEventListener('click', function() {
input.value = ''; input.dispatchEvent(new Event('input')); input.focus();
});
input.addEventListener('input', function() {
var query = input.value.trim();
updateValidationUI(query, iconId, window[resultsRef], clearId);
clearTimeout(timeout);
if (query.length < 3) return;
var cacheKey = serverFunc + "_" + query;
if (searchCache[cacheKey]) {
window[resultsRef] = searchCache[cacheKey];
renderResults(listId, searchCache[cacheKey]);
updateValidationUI(query, iconId, searchCache[cacheKey], clearId);
return;
}
timeout = setTimeout(function() {
google.script.run.withSuccessHandler(function(res) {
searchCache[cacheKey] = res; window[resultsRef] = res;
renderResults(listId, res);
updateValidationUI(input.value.trim(), iconId, res, clearId);
})[serverFunc](query);
}, 300);
});
}
function renderResults(listId, res) {
var dl = document.getElementById(listId);
dl.textContent = '';
res.forEach(function(item) {
var opt = document.createElement('option');
opt.value = item.email || item.name;
dl.appendChild(opt);
});
}
setupAutocomplete(field1, 'groups-list', 'group-validation-icon', 'searchGroups', 'cachedGroups', 'group-clear');
setupAutocomplete(field2, 'teachers-list', 'teacher-validation-icon', 'searchUsers', 'cachedTeachers', 'teacher-clear');
field1.addEventListener('input', function() { if (field1.value.length > 0) { field3.value = ''; document.getElementById('classroom-validation-icon').style.display = 'none'; validate(); } });
field3.addEventListener('input', function() {
var query = field3.value.trim();
var icon = document.getElementById('classroom-validation-icon');
document.getElementById('classroom-clear').style.display = query.length > 0 ? 'block' : 'none';
if (query.length > 0) { field1.value = ''; document.getElementById('group-validation-icon').style.display = 'none'; }
var exact = cachedClassrooms.some(function(c) { return c.name === query; });
icon.style.display = query.length > 0 ? 'inline-block' : 'none';
if (exact) { icon.innerText = 'check_circle'; icon.style.color = 'green'; }
else { icon.innerText = 'error'; icon.style.color = 'orange'; }
validate();
});
buttonNext.addEventListener("click", function() {
buttonNext.disabled = true; buttonNext.textContent = "SAVING...";
var altPassVal = document.getElementById("altPass").checked ? "TRUE" : "FALSE";
var passTypeVal = document.getElementById("passType").value;
var passLengthVal = document.getElementById("passLength").value;
google.script.run.withSuccessHandler(function() {
google.script.run.openSidebarPrepPasswords();
google.script.run.listUsersFormatPassword();
}).saveData(
field1.value,
field2.value,
document.getElementById("changePass").value,
field3.value,
altPassVal,
passTypeVal,
passLengthVal
);
});
</script>
</body>
</html>