-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
227 lines (181 loc) · 7.12 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: Arial;
}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
#footer_msg{
text-align: center;
}
#spreadsheetLink{
text-align: center;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: red;
color: white;
}
</style>
</head>
<body>
<center>
<!-- Main Tab Selection Section -->
<div class="tab">
<button class="tablinks" onclick="openEvent(event, 'Attendance')" id="defaultOpen">Attendance</button>
<button class="tablinks" onclick="openEvent(event, 'Restroom')">Restroom</button>
</div>
<!-- Attendance Tab Section -->
<div id="Attendance" class="tabcontent">
<h3>Attendance</h3>
<form id="attendanceForm">
<p><em>Select your name from the list</em></p>
<select id="attendanceSelect">
<option disabled selected value> -- select -- </option>
<? var options = getStudents()
for (var i = 0; i < options.length; i++) { ?>
<option><?= options[i] ?></option>
<? } ?>
</select>
<input id="attendanceBtn" type="button" onclick="attendanceSubmit()" value="Submit">
</form>
<br>
<div id="student_status"></div>
</div>
<!-- Restroom Tab Section -->
<div id="Restroom" class="tabcontent">
<h3>Restroom</h3>
<form id="restroomForm">
<p><em>Select your name from the list</em></p>
<select id="restroomSelect">
<option disabled selected value> -- select -- </option>
<? var options = getStudents()
for (var i = 0; i < options.length; i++) { ?>
<option><?= options[i] ?></option>
<? } ?>
</select>
<input id="restroomBtn" type="button" onclick="restroomSubmit()" value="Log">
</form>
<br>
<div id="restroom_status"></div>
</div>
</center>
<div id="student_count"></div>
<center>
<div class="footer">
<p id="footer_msg">For educational and demonstration purposes. View the spreadsheet or reset the data below.</p>
<h4 id="spreadsheetLink">
<a href="https://github.com/exmelendez/google-apps-script/tree/student_attendance" target="_blank">
<img src="https://image.flaticon.com/icons/svg/25/25231.svg" alt="Visit Github Page" width="42" height="42" border="0" title="Visit Github Page"></a>
<a href="https://docs.google.com/spreadsheets/d/1WCgggJcrpLfhtxrBjurWriF7Y5xrMVLXypvfNZfYoYk/edit?usp=sharing" target="_blank">
<img src="http://icons.iconarchive.com/icons/dtafalonso/android-lollipop/512/Sheets-icon.png" alt="View active Spreadsheet" width="42" height="42" border="0" title="View active spreadsheet"></a>
<a href="#"><img src="https://cdn3.iconfinder.com/data/icons/basic-icon-set/32/test-13-512.png" alt="Clear data from Spreadsheet" width="42" height="42" border="0" title="Clear spreadsheet data" id="refreshBtn"></a>
</h4>
</div>
</center>
<script>
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
google.script.run.withSuccessHandler(updateStudentCount).nameSearchCurrentSize("null", "totalCount");
document.querySelector('#refreshBtn').addEventListener("click", resetSS);
function attendanceSubmit(){
document.getElementById("attendanceBtn").disabled = true;
var name = document.getElementById("attendanceSelect").value;
google.script.run.withSuccessHandler(attendanceSuccess).checkIn(name, "attendance");
}
function attendanceSuccess(statusMsg){
var div = document.getElementById("student_status");
div.innerHTML = statusMsg;
document.getElementById("attendanceForm").reset();
document.getElementById("attendanceBtn").disabled = false;
google.script.run.withSuccessHandler(updateStudentCount).nameSearchCurrentSize("null", "totalCount");
}
function restroomSubmit(){
document.getElementById("restroomBtn").disabled = true;
var name = document.getElementById("restroomSelect").value;
google.script.run.withSuccessHandler(restroomSuccess).checkIn(name, "restroom");
}
function restroomSuccess(statusMsg){
var div = document.getElementById("restroom_status");
div.innerHTML = statusMsg;
document.getElementById("restroomForm").reset();
document.getElementById("restroomBtn").disabled = false;
}
function updateStudentCount(studentCount){
var studentCountDiv = document.getElementById("student_count");
studentCountDiv.innerHTML = studentCount;
}
function resetRows(){
var div = document.getElementById("student_status");
google.script.run.removeRows();
div.innerHTML = "Spreadsheet reset";
}
/* Function below for the tab selections */
function openEvent(evt, action) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(action).style.display = "block";
evt.currentTarget.className += " active";
if (action === "Attendance"){
var div = document.getElementById("restroom_status");
div.innerHTML = "";
}
else {
var div = document.getElementById("student_status");
div.innerHTML = "";
}
}
function resetSS() {
var attendanceDiv = document.getElementById("student_status");
var restroomDiv = document.getElementById("restroom_status");
google.script.run.removeRows();
google.script.run.withSuccessHandler(updateStudentCount).nameSearchCurrentSize("null", "totalCount");
attendanceDiv.innerHTML = "Spreadsheet reset";
restroomDiv.innerHTML = "Spreadsheet reset";
}
</script>
</body>
</html>