-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
744 lines (683 loc) · 28.7 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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Meta and Title -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Christmas 2024 Invitation</title>
<!-- Fonts and Libraries -->
<link href="https://fonts.googleapis.com/css2?family=Overpass:wght@400;600&family=Ubuntu+Mono&display=swap" rel="stylesheet">
<!-- Include jsPDF and jsPDF AutoTable -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.23/jspdf.plugin.autotable.min.js"></script>
<!-- Include XLSX Library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<!-- Styles -->
<style>
/* Adjusted font sizes decreased by approximately 1 point */
body {
font-family: 'Overpass', sans-serif;
background: linear-gradient(135deg, #ff6f61, #ffad60, #ffd700);
color: #333;
margin: 0;
padding: 4px 0;
display: flex;
align-items: flex-start;
justify-content: center;
min-height: 100vh;
background-size: cover;
}
.wrapper {
background: #ffffff;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
border-radius: 8px;
padding: 20px;
margin: 20px;
opacity: 0.95;
max-width: 1200px;
width: 90%;
}
.header {
background: #cc0000;
color: white;
text-align: center;
font-size: 1.6167em; /* Reduced font size */
border-radius: 8px 8px 0 0;
padding: 10px; /* Adjusted padding */
margin-bottom: 0; /* Removes margin below the header */
}
.header h5 {
margin: 4px 0px;
padding: 0; /* Ensures no extra space inside the h1 */
letter-spacing: 1px;
}
.content {
padding: 15px;
line-height: 1.6;
overflow-y: auto;
}
.lists-container {
display: flex;
justify-content: space-between;
gap: 20px;
}
.list {
flex: 1;
max-width: 50%;
}
.list h2 {
color: #cc0000;
font-size: 1.3167em; /* Decreased from 1.4em */
text-align: center;
}
.list .sorting-buttons {
display: flex;
justify-content: center;
gap: 10px;
margin-bottom: 10px;
}
.list .sorting-buttons button {
padding: 5px 10px;
background-color: #cc0000;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-family: 'Overpass', sans-serif;
font-size: 0.9167em; /* Decreased from 1em */
}
.list .sorting-buttons button:hover {
background-color: #aa0000;
}
.list .list-header,
ul li {
display: flex;
align-items: center;
}
.list .list-header {
background: #fff;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
.list .list-header div,
ul li div {
padding: 8px 5px;
font-size: 0.9167em; /* Decreased from 1em */
min-height: 40px;
display: flex;
align-items: center;
box-sizing: border-box;
}
.list .list-header div:not(.delete-placeholder),
ul li div:not(.delete-cell) {
border-right: 1px solid #ccc;
}
.list .list-header div:last-child,
ul li div:last-child {
border-right: none;
}
.list .list-header .checkbox-placeholder,
ul li .checkbox-cell {
flex-shrink: 0;
width: 40px;
justify-content: center;
border-left: 1px solid #ccc;
}
.list .list-header .checkbox-placeholder {
border-left: none;
}
/* Make field titles bold */
.list .list-header .name-title,
.list .list-header .company-title,
.list .list-header .comments-title {
font-weight: bold;
}
/* Adjusted Name field to be slightly longer */
.list .list-header .name-title,
ul li .person-name,
ul li .name-input {
flex: 0 0 30%; /* Increased from 20% */
}
/* Adjusted Company field to be slightly shorter */
.list .list-header .company-title,
ul li .company-text,
ul li .company-input {
flex: 0 0 20%; /* Decreased from 25% */
}
/* Comments field remains the same */
.list .list-header .comments-title,
ul li .comments-text,
ul li .comments-input {
flex: 1;
}
.list .list-header .delete-placeholder,
ul li .delete-cell {
flex-shrink: 0;
width: 80px;
display: flex;
justify-content: center;
align-items: center;
border-right: none;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
border-bottom: 1px solid #ccc;
}
ul li {
border-top: 1px solid #ccc;
background: #fff;
}
ul li.not-attending {
background: #f1f1f1;
}
ul li .select-person {
margin: 0;
width: 20px;
height: 20px;
}
/* Use Ubuntu Mono font for field entries and make it smaller */
ul li .person-name,
ul li .company-text,
ul li .comments-text,
ul li .name-input,
ul li .company-input,
ul li .comments-input {
font-family: 'Ubuntu Mono', monospace;
font-size: 0.8333em; /* Decreased further to make Ubuntu font smaller */
padding: 8px 5px;
min-height: 40px;
display: flex;
align-items: center;
box-sizing: border-box;
width: 100%;
}
ul li .name-input,
ul li .company-input,
ul li .comments-input {
border: 1px solid #ccc;
display: none; /* Hidden by default */
padding: 5px;
}
ul li .person-name,
ul li .company-text,
ul li .comments-text {
overflow: hidden;
text-overflow: ellipsis;
}
ul li button {
margin: 0 10px;
padding: 5px 10px;
background-color: #cc0000;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-family: 'Overpass', sans-serif;
font-size: 0.9167em; /* Decreased from 1em */
}
ul li button:hover {
background-color: #aa0000;
}
.not-attending .person-name {
color: #555;
font-style: italic;
}
.button-group {
display: flex;
flex-direction: row;
gap: 10px;
margin-top: 20px;
flex-wrap: wrap;
justify-content: center;
background-color: #ffffff;
padding: 10px;
position: sticky;
bottom: 0;
left: 0;
right: 0;
border-top: 1px solid #ccc;
}
.button-group button {
padding: 10px 20px;
font-size: 0.9167em; /* Decreased from 1em */
margin: 5px;
border: none;
background-color: #cc0000;
color: white;
cursor: pointer;
border-radius: 5px;
font-family: 'Overpass', sans-serif;
}
.button-group button:hover {
background-color: #aa0000;
}
.button-group input[type="file"] {
display: none;
}
/* Notification Styles */
#notification {
display: none;
text-align: center;
padding: 10px;
color: green;
font-weight: bold;
font-size: 0.9167em; /* Decreased from 1em */
}
</style>
</head>
<body>
<div class="wrapper">
<div class="header">
<h5>CCA Software Christmas RSVP List Tool v1.0</h5>
<h5>Created by Dean Thomson (2024)</h5>
</div>
<div class="content">
<div class="lists-container">
<div class="list attending">
<h2>Attending</h2>
<!-- Sorting Buttons -->
<div class="sorting-buttons">
<button onclick="sortList('attending', 'name')">Sort by Name</button>
<button onclick="sortList('attending', 'company')">Sort by Company</button>
</div>
<!-- Column Titles -->
<div class="list-header" id="attending-header">
<div class="checkbox-placeholder"></div>
<div class="name-title">Name</div>
<div class="company-title">Company</div>
<div class="comments-title">Comments</div>
<div class="delete-placeholder"></div>
</div>
<ul id="attending-list">
<!-- The list items will be populated by JavaScript -->
</ul>
</div>
<div class="list not-attending">
<h2>Not Attending</h2>
<!-- Sorting Buttons -->
<div class="sorting-buttons">
<button onclick="sortList('not-attending', 'name')">Sort by Name</button>
<button onclick="sortList('not-attending', 'company')">Sort by Company</button>
</div>
<!-- Column Titles -->
<div class="list-header" id="not-attending-header">
<div class="checkbox-placeholder"></div>
<div class="name-title">Name</div>
<div class="company-title">Company</div>
<div class="comments-title">Comments</div>
<div class="delete-placeholder"></div>
</div>
<ul id="not-attending-list">
<!-- The list items will be populated by JavaScript -->
</ul>
</div>
</div>
</div>
<div class="button-group">
<button onclick="addPersonPrompt('attending')">Add Attendee</button>
<button onclick="addPersonPrompt('not-attending')">Add Not Attending</button>
<button onclick="saveList()">Save List</button>
<button onclick="undo()">Undo</button>
<button onclick="saveToPDF()">Save as PDF</button>
<button onclick="saveToSpreadsheet()">Save as Spreadsheet</button>
</div>
<!-- Notification Area -->
<div id="notification"></div>
</div>
<script>
// Data arrays to hold the guest information
let attendingGuests = [];
let notAttendingGuests = [];
// Action history for undo functionality
let actionHistory = [];
// Sorting state
let sortStates = {
'attending': { field: null, order: 'asc' },
'not-attending': { field: null, order: 'asc' }
};
function renderList() {
// Clear existing list items
document.getElementById('attending-list').innerHTML = '';
document.getElementById('not-attending-list').innerHTML = '';
// Render attending guests
attendingGuests.forEach((guest, index) => {
const listItem = createListItem(guest, 'attending', index);
document.getElementById('attending-list').appendChild(listItem);
});
// Render not attending guests
notAttendingGuests.forEach((guest, index) => {
const listItem = createListItem(guest, 'not-attending', index);
document.getElementById('not-attending-list').appendChild(listItem);
});
}
function createListItem(guest, listType, index) {
const listItem = document.createElement('li');
if (listType === 'not-attending') {
listItem.classList.add('not-attending');
}
listItem.innerHTML = `
<div class="checkbox-cell">
<input type="checkbox" class="select-person" onclick="toggleEditMode(this)">
</div>
<div class="person-name">${guest.name}</div>
<input type="text" class="name-input" value="${guest.name}" style="display: none;">
<div class="company-text">${guest.company || ''}</div>
<input type="text" class="company-input" placeholder="Company" value="${guest.company || ''}" style="display: none;">
<div class="comments-text">${guest.comments || ''}</div>
<input type="text" class="comments-input" placeholder="Comments" value="${guest.comments || ''}" style="display: none;">
<div class="delete-cell">
<button onclick="removePerson('${listType}', ${index})">Delete</button>
</div>
`;
return listItem;
}
function toggleEditMode(checkbox) {
const listItem = checkbox.closest('li');
const isEditing = checkbox.checked;
const nameInput = listItem.querySelector('.name-input');
const nameText = listItem.querySelector('.person-name');
const companyInput = listItem.querySelector('.company-input');
const companyText = listItem.querySelector('.company-text');
const commentsInput = listItem.querySelector('.comments-input');
const commentsText = listItem.querySelector('.comments-text');
if (isEditing) {
nameInput.style.display = 'flex';
nameText.style.display = 'none';
companyInput.style.display = 'flex';
companyText.style.display = 'none';
commentsInput.style.display = 'flex';
commentsText.style.display = 'none';
} else {
// Save current state for undo
const listType = listItem.parentElement.id === 'attending-list' ? 'attending' : 'not-attending';
const index = Array.from(listItem.parentElement.children).indexOf(listItem);
const guestList = listType === 'attending' ? attendingGuests : notAttendingGuests;
const oldGuest = { ...guestList[index] };
// Update guest data with input values
guestList[index].name = nameInput.value.trim() || guestList[index].name;
guestList[index].company = companyInput.value.trim();
guestList[index].comments = commentsInput.value.trim();
nameText.textContent = guestList[index].name || 'Name';
companyText.textContent = guestList[index].company || '';
commentsText.textContent = guestList[index].comments || '';
nameInput.style.display = 'none';
nameText.style.display = 'flex';
companyInput.style.display = 'none';
companyText.style.display = 'flex';
commentsInput.style.display = 'none';
commentsText.style.display = 'flex';
// Save action to history
actionHistory.push({
type: 'edit',
listType: listType,
index: index,
oldGuest: oldGuest,
newGuest: { ...guestList[index] }
});
// Save the list after editing
saveList();
}
}
function addPerson(guest, listType) {
// Save current state for undo
actionHistory.push({
type: 'add',
listType: listType,
guest: guest
});
if (listType === 'attending') {
attendingGuests.push(guest);
} else {
notAttendingGuests.push(guest);
}
renderList();
// Automatically save the list after adding a new entry
saveList();
}
function addPersonPrompt(listType) {
const personName = prompt("Enter the name of the person:");
if (personName) {
addPerson({ name: personName, company: '', comments: '' }, listType);
}
}
function removePerson(listType, index) {
const guestList = listType === 'attending' ? attendingGuests : notAttendingGuests;
const removedGuest = guestList[index];
// Save action to history
actionHistory.push({
type: 'delete',
listType: listType,
index: index,
guest: removedGuest
});
guestList.splice(index, 1);
renderList();
// Automatically save the list after deleting an entry
saveList();
}
function sortList(listType, field) {
const guestList = listType === 'attending' ? attendingGuests : notAttendingGuests;
const prevState = [...guestList.map(guest => ({ ...guest }))];
// Determine sort order
let order = 'asc';
if (sortStates[listType].field === field && sortStates[listType].order === 'asc') {
order = 'desc';
}
// Perform sorting
guestList.sort((a, b) => {
let fieldA = (a[field] || '').toLowerCase();
let fieldB = (b[field] || '').toLowerCase();
if (fieldA < fieldB) return order === 'asc' ? -1 : 1;
if (fieldA > fieldB) return order === 'asc' ? 1 : -1;
return 0;
});
// Update sort state
sortStates[listType] = { field: field, order: order };
// Save action to history
actionHistory.push({
type: 'sort',
listType: listType,
prevState: prevState,
field: field,
order: order
});
renderList();
// Save the list after sorting
saveList();
}
function undo() {
if (actionHistory.length === 0) {
alert('Nothing to undo.');
return;
}
const lastAction = actionHistory.pop();
if (lastAction.type === 'add') {
const guestList = lastAction.listType === 'attending' ? attendingGuests : notAttendingGuests;
guestList.pop();
} else if (lastAction.type === 'delete') {
const guestList = lastAction.listType === 'attending' ? attendingGuests : notAttendingGuests;
guestList.splice(lastAction.index, 0, lastAction.guest);
} else if (lastAction.type === 'edit') {
const guestList = lastAction.listType === 'attending' ? attendingGuests : notAttendingGuests;
guestList[lastAction.index] = lastAction.oldGuest;
} else if (lastAction.type === 'sort') {
const guestList = lastAction.listType === 'attending' ? attendingGuests : notAttendingGuests;
guestList.length = 0;
guestList.push(...lastAction.prevState);
sortStates[lastAction.listType] = { field: null, order: 'asc' };
}
renderList();
// Save the list after undo
saveList();
}
// Define your API token (should be stored securely)
const apiToken = 'f6210ea7848bf16861d850de1b7f5449ce1e2b4bfdf6b27bfeeb9019b0645f93'; // Replace with the same token set in PHP
function saveList(callback) {
// Update guest data with current input values
updateGuestData();
// Prepare data as JSON
const data = JSON.stringify({
attendingGuests: attendingGuests,
notAttendingGuests: notAttendingGuests
});
// Send data to the server via AJAX
const xhr = new XMLHttpRequest();
xhr.open("POST", "save_guest_list.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Authorization", "Bearer " + apiToken); // Set Authorization header
xhr.onload = function() {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
if (response.status === 'success') {
showNotification(response.message, 'green');
if (callback) callback();
} else {
showNotification(response.message, 'red');
}
} else {
try {
const response = JSON.parse(xhr.responseText);
showNotification(response.message || 'Error saving data', 'red');
} catch (e) {
showNotification('Error saving data', 'red');
}
}
};
xhr.onerror = function() {
showNotification('Error saving data.', 'red');
};
xhr.send("data=" + encodeURIComponent(data));
}
function loadGuestList() {
// Send request to the server via AJAX
const xhr = new XMLHttpRequest();
xhr.open("GET", "load_guest_list.php", true);
xhr.setRequestHeader("Authorization", "Bearer " + apiToken); // Set Authorization header
xhr.onload = function() {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
if (response.status === 'success') {
attendingGuests = response.data.attendingGuests || [];
notAttendingGuests = response.data.notAttendingGuests || [];
renderList();
showNotification('List loaded successfully!', 'green');
} else {
showNotification(response.message, 'red');
}
} else {
try {
const response = JSON.parse(xhr.responseText);
showNotification(response.message || 'Error loading data', 'red');
} catch (e) {
showNotification('Error loading data', 'red');
}
}
};
xhr.onerror = function() {
showNotification('Error loading data.', 'red');
};
xhr.send();
}
// Function to update guest data from input fields (Ensure this function is defined)
function updateGuestData() {
// Update attending guests
const attendingListItems = document.querySelectorAll('#attending-list li');
attendingListItems.forEach((item, index) => {
const nameInput = item.querySelector('.name-input');
const companyInput = item.querySelector('.company-input');
const commentsInput = item.querySelector('.comments-input');
attendingGuests[index].name = nameInput.value.trim() || attendingGuests[index].name;
attendingGuests[index].company = companyInput.value.trim();
attendingGuests[index].comments = commentsInput.value.trim();
});
// Update not attending guests
const notAttendingListItems = document.querySelectorAll('#not-attending-list li');
notAttendingListItems.forEach((item, index) => {
const nameInput = item.querySelector('.name-input');
const companyInput = item.querySelector('.company-input');
const commentsInput = item.querySelector('.comments-input');
notAttendingGuests[index].name = nameInput.value.trim() || notAttendingGuests[index].name;
notAttendingGuests[index].company = companyInput.value.trim();
notAttendingGuests[index].comments = commentsInput.value.trim();
});
}
// Save the list when the page loads
window.onload = function() {
loadGuestList();
}
// Function to show notifications (Ensure this function is defined)
function showNotification(message, color) {
const notification = document.getElementById('notification');
notification.style.display = 'block';
notification.style.color = color;
notification.textContent = message;
setTimeout(() => {
notification.style.display = 'none';
}, 3000);
}
// Functions to save to PDF and Spreadsheet (Ensure these functions are defined)
function saveToPDF() {
updateGuestData();
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.text('Christmas 2024 Invitation List', 14, 20);
// Prepare data for the table
const tableColumn = ["Status", "Name", "Company", "Comments"];
const tableRows = [];
attendingGuests.forEach((guest) => {
tableRows.push(["Attending", guest.name, guest.company, guest.comments]);
});
notAttendingGuests.forEach((guest) => {
tableRows.push(["Not Attending", guest.name, guest.company, guest.comments]);
});
// AutoTable options
doc.autoTable({
head: [tableColumn],
body: tableRows,
startY: 30,
styles: { fontSize: 10 },
headStyles: { fillColor: [204, 0, 0] },
columnStyles: {
0: { cellWidth: 30 }, // Status
1: { cellWidth: 40 }, // Name
2: { cellWidth: 50 }, // Company
3: { cellWidth: 60 }, // Comments
},
margin: { left: 14, right: 14 },
didDrawPage: function (data) {
// Header
doc.setFontSize(16);
doc.setTextColor(40);
doc.text("Christmas 2024 Invitation List", data.settings.margin.left, 20);
},
});
doc.save('Christmas_Invitation_List.pdf');
}
function saveToSpreadsheet() {
updateGuestData();
let wb = XLSX.utils.book_new();
let ws_data = [['Status', 'Name', 'Company', 'Comments']];
attendingGuests.forEach((guest) => {
ws_data.push(['Attending', guest.name, guest.company, guest.comments]);
});
notAttendingGuests.forEach((guest) => {
ws_data.push(['Not Attending', guest.name, guest.company, guest.comments]);
});
let ws = XLSX.utils.aoa_to_sheet(ws_data);
// Set column widths
ws['!cols'] = [
{ wch: 15 }, // Status
{ wch: 20 }, // Name
{ wch: 30 }, // Company
{ wch: 30 }, // Comments
];
XLSX.utils.book_append_sheet(wb, ws, 'Christmas Invitation List');
XLSX.writeFile(wb, 'Christmas_Invitation_List.xlsx');
}
</script>
</body>
</html>