-
Notifications
You must be signed in to change notification settings - Fork 0
/
student-existing-meetings.html
230 lines (218 loc) · 11 KB
/
student-existing-meetings.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
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<?!= include('bootstrap'); ?>
<?!= include('style'); ?>
<style type="text/css">
body {
background-color: #000;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
}
</style>
<script>
function cancelCommitment(pairId,tutorName) {
if (tutorName) {
var message = "Are you sure? If so, we'll send an email to the tutor, " + tutorName + ".";
}
else {
var message = "Are you sure you want to cancel this request?";
}
var lg = confirm(message);
if (lg) {
var submit = document.getElementById("cancelCommitmentSubmit" + pairId);
submit.value = "Please Wait...";
submit.disabled = true;
google.script.run.withFailureHandler(function(response){
console.log(response);
submit.value = "Free me from this commitment";
submit.disabled = false;
alert("There was an error. Please try again.");
}).withSuccessHandler(function(response) {
if (!response.success) {
submit.value = "Cancel this commitment";
submit.disabled = false;
return alert(response.message);
}
alert("This commitment has been canceled. Thank you!");
submit.style.display = "none";
}).studentCancelCommitment(document.getElementById("cancelCommitment" + pairId));
}
return false;
}
</script>
</head>
<body>
<div class="page">
<div class="translucent-background">
<div class="container">
<div class="row" style="padding-bottom: 5vh;">
<div class="col-sm-12">
<h1>Manage your Tutoring Commitments</h1>
<a href="<?= baseAppUrl ?>?page=home" id="homeLink">Back to home</a>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<? if (!isLoggedIn()) { ?>
<p>Please <a href="<?= signInLink ?>">sign in</a> using your <?= orgAccountName ?> account to view this page.</p>
<? }
else {
?>
<p>
Hi <?= getFirstName() ?> <?= getLastName() ?>,</p>
<?
var studentEmail = email;
var tutorSheet = SpreadsheetApp.openById(sheetId);
var pairingAssignments = tutorSheet.getSheetByName("PairingAssignments");
var range = pairingAssignments.getDataRange();
var rangeArray = range.getValues();
var commitments = {
pending: [],
active: [],
past: []
};
rangeArray.shift();
for (var i = 0; i < rangeArray.length; i++) {
var row = rangeArray[i];
if (row[2] == studentEmail) {
Logger.log(row[16] + " is row 16");
if (row[16] == true) {//is active
commitments.active.push(row);
}
else if (!row[13] && row[16] !== false) { //is pending
commitments.pending.push(row);
}
else { //is in the past
commitments.past.push(row);
}
}
}
if (commitments.active.length + commitments.past.length + commitments.pending.length == 0) {
?>
<p>Unfortunately, it seems that you haven't requested a tutor. Want a tutor? <a href="<?= baseAppUrl ?>?page=student-new-request">head over here</a>.</p>
<?
}
else { ?>
<p>Here are your tutoring commitments:</p>
<?
//let's go look up the phone numbers in one shreadsheet api
var tutorList = tutorSheet.getSheetByName("TutorList");
var range1 = tutorList.getDataRange();
var rangeValues = range1.getValues();
//let's convert it into an object of email:phone#
var tutorPhoneNumbers = {};
for (var i = 1; i < rangeValues.length; i++) {
var row2 = rangeValues[i];
//row[0] = email; row[1] = phone; row[2] = json of available slots; row[3] = json of occupied slots
tutorPhoneNumbers[row2[0]] = row2[1];
}
for (var type in commitments) {
if (commitments.hasOwnProperty(type)) {
if (commitments[type].length > 0) { ?>
<h2 style="text-transform: capitalize;"><?= type ?></h2>
<table border="1" style="background-color: #111;">
<tr>
<? if (type != "pending") { ?><th>Tutor</th><? }?>
<th>Subject</th>
<th>Course</th>
<th>Teacher</th>
<th>Duration</th>
<? if (type != "pending") { ?><th>Meeting Time and Place</th><? }?>
<th>Actions and Notes</th>
</tr>
<?
commitments[type].forEach(function(commitment) {
var duration = commitment[10];
var durationName = getDurationName(duration);
var tutorEmail = commitment[13];
//go look up the phone on the tutorlist
?>
<tr>
<? if (type != "pending") { ?>
<td><!-- student info -->
<?
if (!tutorEmail) { ?>
N/A
<? } else { ?>
<?= getFirstName(tutorEmail) ?> <?= getLastName(tutorEmail) ?><br />
<a href="mailto:<?= tutorEmail ?>"><?= tutorEmail ?></a><br />
<?= formatPhone(tutorPhoneNumbers[tutorEmail]); ?>
<? } ?>
</td>
<? } ?>
<td><!-- subject -->
<?= commitment[4] ?>
</td>
<td><!-- course -->
<?= commitment[7] ?>
</td>
<td><!-- teacher -->
<a href="mailto:<?=commitment[8]?>"><?= getFirstName(commitment[8]) ?> <?= getLastName(commitment[8]) ?></a>
</td>
<td><!-- duration -->
<?= durationName ?>
</td>
<? if (type != "pending") { ?><td><!-- meeting time and place -->
<?
if (!tutorEmail) { ?>
N/A
<? } else {
var time = commitment[14];
var day = time.substring(0,3);
var period = time.substring(3,5);
var location = JSON.parse(commitment[9])[time];?>
<?= getDayName(day) ?><br />
<?= getPeriodName(period) ?><br />
<?= getLocationName(location) ?>
<? } ?>
</td><? } ?>
<td><!-- actions -->
<ul>
<?
if (type == "pending") { ?>
<li>
<form onSubmit="return cancelCommitment(<?= commitment[0] ?>)"
id="cancelCommitment<?= commitment[0] ?>">
<input type="hidden" name="userEmail" value="<?= email ?>">
<input type="hidden" name="userHash" value="<?= generateHash_() ?>">
<input type="hidden" name="pairId" value="<?= commitment[0] ?>">
<input type="submit" class="actionLink" id="cancelCommitmentSubmit<?= commitment[0] ?>" value="Cancel this request">
</form>
</li>
<? } else if (commitment[16] != false) { ?>
<li>
<form onSubmit="return cancelCommitment(<?= commitment[0] ?>,<?= getFirstName(tutorEmail) ?>)"
id="cancelCommitment<?= commitment[0] ?>">
<input type="hidden" name="userEmail" value="<?= email ?>">
<input type="hidden" name="userHash" value="<?= generateHash_() ?>">
<input type="hidden" name="pairId" value="<?= commitment[0] ?>">
<input type="submit" class="actionLink" id="cancelCommitmentSubmit<?= commitment[0] ?>" value="Cancel this commitment">
</form>
</li>
<? } ?>
<li>
<a href="<?= baseAppUrl ?>?page=student-move-request&pairid=<?= commitment[0] ?>"><?= getMoveJargon(commitment[16]) ?></a>
</li>
</ul>
<? if (commitment[18] != false) { ?>
<br />
<br />
<p>Notes: <?= commitment[18] ?> </p>
<? } ?>
</td>
</tr>
<? }); ?>
</table>
<?
} } } } }
?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>