-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
481 lines (424 loc) · 19.1 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<!DOCTYPE html>
<html>
<head>
<base target="_top" />
<style>
/* CSS styles for the sidebar */
.sidebar {
width: 100%;
font-family: Arial, sans-serif;
background-color: #f2f2f2;
padding: 20px;
border-radius: 5px;
}
.block, .form-group {
margin-bottom: 10px;
display: flex;
flex-direction: column;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin: 5px 0;
font-weight: bold;
}
input[type="text"], select {
width: 100%;
padding: 10px;
margin: 5px 0;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 16px;
}
.blue {
background-color: #007bff;
color: white;
padding: 12px 24px;
border: none;
border-radius: 4px;
font-size: 16px;
box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
cursor: pointer;
transition: all 0.3s ease 0s;
margin-bottom: 10px; /* Add spacing between buttons */
display: block; /* Ensure buttons are block-level for full width */
width: 90%; /* Adjust width as needed */
margin-left: auto;
margin-right: auto;
}
.blue:hover {
background-color: #0056b3;
box-shadow: 0px 15px 20px rgba(0, 0, 0, 0.2);
transform: translateY(-7px);
}
/* Additional styling for container to ensure vertical stacking */
#current_templates {
display: flex;
flex-direction: column;
align-items: center; /* Center-align the buttons */
}
.button:hover {
background-color: #1e87d6;
}
.template-title {
display: flex;
align-items: center;
}
.template-item {
display: flex;
align-items: center;
justify-content: space-between;
}
.template-item.selected {
background-color: #f0f0f0;
}
.button-group {
display: flex;
justify-content: space-between;
}
</style>
<!-- Google OAuth Stuff -->
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-auth.js"></script>
<script src="https://cdn.firebase.com/libs/firebaseui/3.5.2/firebaseui.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/3.5.2/firebaseui.css" />
<script>
var firebaseConfig = { // enter the details below
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
};
firebase.initializeApp(firebaseConfig);
</script>
<script>
google.script.run.withSuccessHandler(function(url) {
var uiConfig = {
signInFlow: 'popup',
signInSuccessUrl: url,
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID
],
};
var ui = new firebaseui.auth.AuthUI(firebase.auth());
var user = firebase.auth().currentUser;
if (user) {
document.getElementById("signOut").style.display = "inline-block";
} else {
ui.start('#firebaseui-auth-container', uiConfig);
}
}).webAppUrl();
</script>
<script>
initApp = function() {
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
user.getIdToken().then(function(accessToken) {
document.getElementById('account-details').textContent = JSON.stringify({
displayName: user.displayName,
email: user.email,
emailVerified: user.emailVerified,
phoneNumber: user.phoneNumber,
photoURL: "user.photoURL", // remove quotes to get the photoURL
uid: user.uid,
accessToken: "hidden", // replace "hidden" with accessToken
providerData: "user.providerData" // remove quotes to get the photoURL
}, null, ' ');
});
} else {
document.getElementById('account-details').textContent = '';
}
});
};
window.addEventListener('load', function() {
initApp();
});
</script>
</head>
<body>
<div class="sidebar">
<!-- Create Template Section -->
<div class="block form-group">
<button class="blue oval-button" id="add_template_btn">Create Template</button>
<div id="template_inputs" style="display: none">
<!-- Template input fields -->
<label for="title">Title:</label>
<input type="text" id="title" placeholder="Title" />
<label for="first_name">First Name:</label>
<input type="text" id="first_name" placeholder="First Name" />
<label for="last_name">Last Name:</label>
<input type="text" id="last_name" placeholder="Last Name" />
<label for="teacher_name">Teacher's Name:</label>
<input type="text" id="teacher_name" placeholder="Teacher's Name" />
<label for="class_name">Class Name:</label>
<input type="text" id="class_name" placeholder="Class Name" />
<div class="button-group">
<button class="blue" id="save_template_btn">Save Template</button>
<button class="blue" id="close_edit_mode_btn">Close</button>
</div>
</div>
</div>
<!-- Current Templates Section -->
<div class="form-group">
<h2>Current Templates</h2>
<div id="current_templates"></div>
<button class="blue" id="load_template_btn">Load Template</button>
</div>
<!-- Edit Templates Section -->
<div class="form-group">
<h2>Edit Templates</h2>
<button class="blue" id="show_edit_options_btn">Edit Templates</button>
<div id="edit_template_options" style="display: none;">
<div id="template_to_edit"></div>
<button class="blue" id="edit_template_btn">Edit Selected Template</button>
</div>
</div>
<!-- Delete Templates Section -->
<div class="form-group">
<h2>Delete Templates</h2>
<button class="blue" id="show_delete_options_btn">Delete Templates</button>
<div id="delete_template_options" style="display: none;">
<div id="template_to_delete"></div>
<button class="blue" id="delete_template_btn">Delete Selected Template</button>
</div>
</div>
<button onclick="openPopupFromSidebar()">Open Popup</button>
</div>
<script>
function openPopupFromSidebar() {
google.script.run.openSimplePopup();
}
document.getElementById("add_template_btn").addEventListener("click", function () {
this.style.display = "none";
document.getElementById("template_inputs").style.display = "block";
});
document.getElementById("save_template_btn").addEventListener("click", function() {
var templateData = {
title: document.getElementById("title").value,
firstName: document.getElementById("first_name").value,
lastName: document.getElementById("last_name").value,
teacherName: document.getElementById("teacher_name").value,
className: document.getElementById("class_name").value
};
google.script.run.withSuccessHandler(function() {
alert("Template saved successfully.");
retrieveSavedTemplates();
}).saveTemplate(templateData);
});
function retrieveSavedTemplates() {
google.script.run.withSuccessHandler(renderTemplates).getSavedTemplates();
}
function renderTemplates(templates) {
const container = document.getElementById('current_templates');
container.innerHTML = ''; // Clear existing templates
templates.forEach((template, index) => {
// Create a button for each template
const button = document.createElement('button');
button.className = 'blue'; // Use the same styling as other buttons
button.textContent = template.title || 'Untitled Template';
// Store the index in a data attribute
button.setAttribute('data-index', index);
// Set up the click event listener
button.addEventListener('click', function() {
google.script.run.loadTemplateByIndex(this.getAttribute('data-index'));
});
container.appendChild(button);
});
}
document.getElementById("show_edit_options_btn").addEventListener("click", function() {
document.getElementById("edit_template_options").style.display = "block";
renderTemplatesToEdit();
});
function renderTemplatesToEdit() {
google.script.run.withSuccessHandler(function(templates) {
const container = document.getElementById('template_to_edit');
container.innerHTML = '';
templates.forEach((template, index) => {
const templateDiv = document.createElement('div');
templateDiv.className = 'template-item';
const label = document.createElement('label');
label.htmlFor = 'template_edit_' + index;
label.textContent = template.title || 'Untitled Template';
const radioBtn = document.createElement('input');
radioBtn.type = 'radio';
radioBtn.name = 'template_edit';
radioBtn.value = index;
radioBtn.id = 'template_edit_' + index;
templateDiv.appendChild(label);
templateDiv.appendChild(radioBtn);
container.appendChild(templateDiv);
});
}).getSavedTemplates();
}
document.getElementById("load_template_btn").addEventListener("click", function() {
const selectedTemplateIndex = document.querySelector('input[name="template"]:checked')?.value;
if (selectedTemplateIndex !== undefined) {
google.script.run.loadTemplateByIndex(selectedTemplateIndex);
} else {
alert("Please select a template to load.");
}
});
document.getElementById("edit_template_btn").addEventListener("click", function() {
const selectedTemplateIndex = document.querySelector('input[name="template_edit"]:checked')?.value;
if (selectedTemplateIndex !== undefined) {
google.script.run.withSuccessHandler(function(templateData) {
displayEditForm(templateData, selectedTemplateIndex);
}).getTemplateData(selectedTemplateIndex);
} else {
alert("Please select a template to edit.");
}
});
document.getElementById("show_delete_options_btn").addEventListener("click", function() {
document.getElementById("delete_template_options").style.display = "block";
renderTemplatesToDelete();
});
document.getElementById("delete_template_btn").addEventListener("click", function() {
const selectedTemplateIndex = document.querySelector('input[name="template_delete"]:checked')?.value;
if (selectedTemplateIndex !== undefined) {
google.script.run.withSuccessHandler(function() {
alert("Template deleted successfully.");
retrieveSavedTemplates(); // Refresh the templates list
document.getElementById("delete_template_options").style.display = "none";
}).deleteTemplate(selectedTemplateIndex);
} else {
alert("Please select a template to delete.");
}
});
function renderTemplatesToDelete() {
google.script.run.withSuccessHandler(function(templates) {
const container = document.getElementById('template_to_delete');
container.innerHTML = ''; // Clear any existing content
if (templates.length === 0) {
container.innerHTML = '<p>No templates available to delete.</p>';
return;
}
templates.forEach((template, index) => {
const templateDiv = document.createElement('div');
templateDiv.className = 'template-item';
const label = document.createElement('label');
label.htmlFor = 'template_delete_' + index;
label.textContent = template.title || 'Untitled Template';
const radioBtn = document.createElement('input');
radioBtn.type = 'radio';
radioBtn.name = 'template_delete';
radioBtn.value = index;
radioBtn.id = 'template_delete_' + index;
templateDiv.appendChild(label);
templateDiv.appendChild(radioBtn);
container.appendChild(templateDiv);
});
}).getSavedTemplates();
}
// Corrected event listener for the "Close" button
document.getElementById("close_edit_mode_btn").addEventListener("click", function() {
document.getElementById("template_inputs").style.display = "none";
document.getElementById("add_template_btn").style.display = "block";
resetForm();
});
function resetForm() {
document.getElementById("title").value = "";
document.getElementById("first_name").value = "";
document.getElementById("last_name").value = "";
document.getElementById("teacher_name").value = "";
document.getElementById("class_name").value = "";
}
function loadTemplateByIndex(index) {
google.script.run.withSuccessHandler(function() {
console.log("Template loaded successfully.");
// Optionally, refresh your UI here or give the user feedback
})
.withFailureHandler(function(error) {
console.error("Error loading template: " + error);
})
.loadTemplateByIndex(index);
}
function displayEditForm(templateData, index) {
document.getElementById("template_inputs").style.display = "block";
document.getElementById("title").value = templateData.title;
document.getElementById("first_name").value = templateData.firstName;
document.getElementById("last_name").value = templateData.lastName;
document.getElementById("teacher_name").value = templateData.teacherName;
document.getElementById("class_name").value = templateData.className;
const saveBtn = document.getElementById("save_template_btn");
saveBtn.textContent = "Update Template";
saveBtn.onclick = function() {
updateTemplate(index);
};
}
function updateTemplate(index) {
const updatedTemplateData = {
title: document.getElementById("title").value,
firstName: document.getElementById("first_name").value,
lastName: document.getElementById("last_name").value,
teacherName: document.getElementById("teacher_name").value,
className: document.getElementById("class_name").value
};
google.script.run.withSuccessHandler(function() {
alert("Template updated successfully.");
closeEditMode();
}).saveEditedTemplate(index, updatedTemplateData);
}
function closeEditMode() {
document.getElementById("edit_template_options").style.display = "none";
document.getElementById("current_templates").style.display = "block";
resetFormAndRefreshTemplates();
}
function resetFormAndRefreshTemplates() {
document.getElementById("title").value = "";
document.getElementById("first_name").value = "";
document.getElementById("last_name").value = "";
document.getElementById("teacher_name").value = "";
document.getElementById("class_name").value = "";
const saveBtn = document.getElementById("save_template_btn");
saveBtn.textContent = "Save Template";
saveBtn.onclick = document.getElementById("save_template_btn").addEventListener("click", function() {
var templateData = {
title: document.getElementById("title").value,
firstName: document.getElementById("first_name").value,
lastName: document.getElementById("last_name").value,
teacherName: document.getElementById("teacher_name").value,
className: document.getElementById("class_name").value
};
google.script.run.withSuccessHandler(function() {
alert("Template saved successfully.");
retrieveSavedTemplates();
}).saveTemplate(templateData);
});
retrieveSavedTemplates();
}
retrieveSavedTemplates();
</script>
<!-- Google OAuth Stuff -->
<div class="container center-align">
<br /><br /><h1>Firebase and Google Apps Script</h1><br /><h3>Login using your Google account via Firebase Auth</h3><br /><br />
<div id="firebaseui-auth-container"></div>
<div class="row">
<div class="col s12 m3 offset-m4">
<pre id="account-details" class="left-align"></pre>
</div>
</div>
<button style="display: none" id="signOut" class="firebaseui-idp-button mdl-button mdl-js-button mdl-button--raised firebaseui-idp-google firebaseui-id-idp-button" data-provider-id="google.com" data-upgraded=",MaterialButton">
<span class="firebaseui-idp-icon-wrapper"><img class="firebaseui-idp-icon" alt="" src="https://www.gstatic.com/firebasejs/ui/2.0.0/images/auth/google.svg"></span>
<span class="firebaseui-idp-text firebaseui-idp-text-long">Sign out (Custom)</span>
</button>
<script>
document.getElementById('signOut').addEventListener('click', function(event) {
firebase.auth().signOut();
reload();
});
function reload() {
google.script.run.withSuccessHandler(function(url) {
window.open(url, '_top');
}).webAppUrl();
}
</script>
</body>
</html>