-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.js
More file actions
1843 lines (1574 loc) · 63.2 KB
/
admin.js
File metadata and controls
1843 lines (1574 loc) · 63.2 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
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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Red Cross Philippines Admin Dashboard JavaScript
// Sample data for demonstration
const sampleUsers = [
{
id: 1,
name: "John Doe",
email: "john.doe@email.com",
role: "volunteer",
status: "active",
lastActive: "2024-12-15",
avatar: "JD"
},
{
id: 2,
name: "Jane Smith",
email: "jane.smith@email.com",
role: "staff",
status: "active",
lastActive: "2024-12-14",
avatar: "JS"
},
{
id: 3,
name: "Mike Johnson",
email: "mike.johnson@email.com",
role: "member",
status: "pending",
lastActive: "2024-12-13",
avatar: "MJ"
},
{
id: 4,
name: "Sarah Wilson",
email: "sarah.wilson@email.com",
role: "volunteer",
status: "inactive",
lastActive: "2024-12-10",
avatar: "SW"
},
{
id: 5,
name: "David Brown",
email: "david.brown@email.com",
role: "admin",
status: "active",
lastActive: "2024-12-15",
avatar: "DB"
}
];
const sampleEvents = [
{
id: 1,
title: "Blood Drive - Makati",
date: "2024-12-20",
location: "Makati City Hall",
description: "Monthly blood donation drive in Makati",
status: "upcoming",
volunteers: 15
},
{
id: 2,
title: "First Aid Training",
date: "2024-12-18",
location: "Red Cross Manila",
description: "Basic first aid training for volunteers",
status: "ongoing",
volunteers: 25
},
{
id: 3,
title: "Disaster Relief - Typhoon Response",
date: "2024-12-10",
location: "Quezon City",
description: "Emergency response for typhoon victims",
status: "completed",
volunteers: 50
}
];
const sampleVolunteers = [
{
id: 1,
name: "John Doe",
email: "john.doe@email.com",
role: "Emergency Response",
status: "active",
tasks: ["First Aid", "Search & Rescue"],
phone: "+63 912 345 6789"
},
{
id: 2,
name: "Maria Santos",
email: "maria.santos@email.com",
role: "Blood Services",
status: "active",
tasks: ["Blood Collection", "Donor Care"],
phone: "+63 917 123 4567"
},
{
id: 3,
name: "Carlos Rodriguez",
email: "carlos.rodriguez@email.com",
role: "Training Coordinator",
status: "pending",
tasks: ["Training", "Education"],
phone: "+63 918 987 6543"
}
];
const sampleDonations = [
{
id: 1,
donor: "Anonymous",
amount: 5000,
method: "GCash",
date: "2024-12-15",
status: "completed"
},
{
id: 2,
donor: "Maria Santos",
amount: 2500,
method: "Bank Transfer",
date: "2024-12-14",
status: "completed"
},
{
id: 3,
donor: "John Corporation",
amount: 50000,
method: "Check",
date: "2024-12-13",
status: "pending"
}
];
// Global variables
let currentSection = 'dashboard';
let filteredUsers = [...sampleUsers];
let filteredEvents = [...sampleEvents];
let filteredVolunteers = [...sampleVolunteers];
// Section configuration
const SECTIONS = {
'dashboard': 'dashboard',
'users': 'users',
'events': 'events',
'volunteers': 'volunteers',
'donations': 'donations',
'settings': 'settings'
};
// Initialize the admin dashboard
document.addEventListener('DOMContentLoaded', function() {
console.log('Admin dashboard initializing...');
// Check authentication first
if (!SessionManager.isLoggedIn()) {
console.log('Not logged in, redirecting to login');
window.location.href = 'login.html';
return;
}
// Get current user and check if they're admin
const currentUser = SessionManager.getCurrentUser();
if (!currentUser.isAdmin) {
console.log('Not admin user, redirecting to index');
alert('Access denied. Admin privileges required.');
window.location.href = 'index.html';
return;
}
console.log('Admin user authenticated:', currentUser.name);
// Set up role-based access
setupRoleBasedAccess(currentUser);
initializeDashboard();
setupEventListeners();
loadDashboardData();
loadUsersData();
loadEventsData();
loadVolunteersData();
loadDonationsData();
// Initialize with dashboard section
showSection('dashboard');
// Test all buttons after initialization
setTimeout(() => {
console.log('Running button tests...');
testAllButtons();
}, 1000);
console.log('Admin dashboard initialization complete');
});
// Setup role-based access control
function setupRoleBasedAccess(user) {
// Update profile menu with user info
const profileName = document.querySelector('.text-sm.font-medium.text-gray-800');
const profileRole = document.querySelector('.text-xs.text-gray-500');
if (profileName) profileName.textContent = user.name;
if (profileRole) profileRole.textContent = user.role.charAt(0).toUpperCase() + user.role.slice(1);
// Hide/disable features based on permissions
if (!SessionManager.hasPermission('all')) {
// Hide settings for non-super-admin users
if (!SessionManager.hasPermission('settings')) {
const settingsNav = document.querySelector('[data-section="settings"]');
if (settingsNav) {
settingsNav.parentElement.style.display = 'none';
}
}
// Hide user management for staff and volunteers
if (!SessionManager.hasPermission('users')) {
const usersNav = document.querySelector('[data-section="users"]');
if (usersNav) {
usersNav.parentElement.style.display = 'none';
}
}
// Hide donation tracking for volunteers
if (!SessionManager.hasPermission('donations')) {
const donationsNav = document.querySelector('[data-section="donations"]');
if (donationsNav) {
donationsNav.parentElement.style.display = 'none';
}
}
}
}
// Initialize dashboard
function initializeDashboard() {
// Set initial active section
showSection('dashboard');
// Initialize profile menu with a small delay to ensure DOM is ready
setTimeout(() => {
setupProfileMenu();
}, 100);
// Initialize modals
setupModals();
}
// Handle section navigation
function handleSectionNavigation() {
console.log('Setting up section navigation...');
// Start with dashboard section
showSection('dashboard');
}
// Setup event listeners
function setupEventListeners() {
console.log('Setting up event listeners...');
// Wait a bit to ensure DOM is fully loaded
setTimeout(() => {
console.log('DOM should be ready now...');
// Navigation - updated to work with button elements
const navButtons = document.querySelectorAll('.nav-link');
console.log('Found navigation buttons:', navButtons.length);
if (navButtons.length === 0) {
console.error('NO NAVIGATION BUTTONS FOUND!');
console.log('Available elements with nav-link:', document.querySelectorAll('.nav-link'));
return;
}
setupNavigationButtons(navButtons);
setupOtherEventListeners();
}, 100);
}
// Setup navigation buttons
function setupNavigationButtons(navButtons) {
console.log('Setting up navigation buttons...');
console.log('Found navigation buttons:', navButtons.length);
navButtons.forEach((button, index) => {
const section = button.getAttribute('data-section');
console.log(`Setting up button ${index + 1}:`, section, button);
// Remove any existing event listeners
button.removeEventListener('click', handleNavigationClick);
// Add new event listener
button.addEventListener('click', handleNavigationClick);
// Also add a direct onclick for backup
button.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
console.log('Direct onclick triggered for:', section);
showSection(section);
};
});
console.log('Navigation buttons setup complete');
}
// Navigation click handler
function handleNavigationClick(e) {
e.preventDefault();
e.stopPropagation();
const section = this.getAttribute('data-section');
console.log('Navigation clicked:', section, this);
// Show the section
showSection(section);
}
// Setup other event listeners
function setupOtherEventListeners() {
console.log('Setting up other event listeners...');
// Search and filter functionality
setupSearchAndFilters();
// Modal buttons
const addEventBtn = document.getElementById('addEventBtn');
if (addEventBtn) {
addEventBtn.addEventListener('click', () => openModal('eventModal'));
}
const addUserBtn = document.getElementById('addUserBtn');
if (addUserBtn) {
addUserBtn.addEventListener('click', () => openModal('userModal'));
}
const addVolunteerBtn = document.getElementById('addVolunteerBtn');
if (addVolunteerBtn) {
addVolunteerBtn.addEventListener('click', () => openModal('userModal')); // Using userModal for volunteers too
}
// Quick action buttons in dashboard
const quickAddEvent = document.getElementById('quickAddEvent');
if (quickAddEvent) {
quickAddEvent.addEventListener('click', () => openModal('eventModal'));
}
const quickAddUser = document.getElementById('quickAddUser');
if (quickAddUser) {
quickAddUser.addEventListener('click', () => openModal('userModal'));
}
const quickExportData = document.getElementById('quickExportData');
if (quickExportData) {
quickExportData.addEventListener('click', () => {
showNotification('Export functionality coming soon!', 'info');
});
}
const quickViewReports = document.getElementById('quickViewReports');
if (quickViewReports) {
quickViewReports.addEventListener('click', () => {
showNotification('Reports functionality coming soon!', 'info');
});
}
// Form submissions
const eventForm = document.getElementById('eventForm');
if (eventForm) {
eventForm.addEventListener('submit', handleEventSubmit);
}
// Dashboard form submissions
const dashboardEventForm = document.getElementById('dashboardEventForm');
if (dashboardEventForm) {
dashboardEventForm.addEventListener('submit', handleDashboardEventSubmit);
}
const dashboardUserForm = document.getElementById('dashboardUserForm');
if (dashboardUserForm) {
dashboardUserForm.addEventListener('submit', handleDashboardUserSubmit);
}
// Dashboard form cancel buttons
const cancelDashboardEvent = document.getElementById('cancelDashboardEvent');
if (cancelDashboardEvent) {
cancelDashboardEvent.addEventListener('click', () => {
hideEventForm();
});
}
const cancelEventManagement = document.getElementById('cancelEventManagement');
if (cancelEventManagement) {
cancelEventManagement.addEventListener('click', () => {
hideEventManagementForm();
});
}
const cancelDashboardUser = document.getElementById('cancelDashboardUser');
if (cancelDashboardUser) {
cancelDashboardUser.addEventListener('click', () => {
hideDashboardUserForm();
});
}
const cancelUserManagement = document.getElementById('cancelUserManagement');
if (cancelUserManagement) {
cancelUserManagement.addEventListener('click', () => {
hideUserManagementForm();
});
}
const cancelVolunteerStaff = document.getElementById('cancelVolunteerStaff');
if (cancelVolunteerStaff) {
cancelVolunteerStaff.addEventListener('click', () => {
hideVolunteerStaffForm();
});
}
const cancelDonation = document.getElementById('cancelDonation');
if (cancelDonation) {
cancelDonation.addEventListener('click', () => {
hideDonationForm();
});
}
// Volunteer modal buttons
const cancelVolunteerBtn = document.getElementById('cancelVolunteerBtn');
if (cancelVolunteerBtn) {
cancelVolunteerBtn.addEventListener('click', () => closeModal('volunteerModal'));
}
// Volunteer form submission
const volunteerForm = document.getElementById('volunteerForm');
if (volunteerForm) {
volunteerForm.addEventListener('submit', handleVolunteerSubmit);
}
const userForm = document.getElementById('userForm');
if (userForm) {
userForm.addEventListener('submit', handleUserSubmit);
}
// Profile menu logout
const logoutLink = document.querySelector('a[href="#"]:last-child');
if (logoutLink && logoutLink.textContent.includes('Logout')) {
logoutLink.addEventListener('click', function(e) {
e.preventDefault();
if (confirm('Are you sure you want to logout?')) {
showNotification('Logging out...', 'info');
setTimeout(() => {
SessionManager.logout();
window.location.href = 'login.html';
}, 1000);
}
});
}
// Notification bell button
const notificationBtn = document.querySelector('button.relative.p-2');
if (notificationBtn) {
notificationBtn.addEventListener('click', () => {
showNotification('No new notifications', 'info');
});
}
}
// Show specific section
function showSection(sectionName) {
console.log('Switching to section:', sectionName);
// First, let's check what sections exist
const allSections = document.querySelectorAll('.admin-section');
console.log('All sections found:', allSections.length);
allSections.forEach(section => {
console.log('Section ID:', section.id);
});
// Hide all sections
document.querySelectorAll('.admin-section').forEach(section => {
section.classList.add('hidden');
});
// Show selected section
const targetSection = document.getElementById(`${sectionName}-section`);
if (targetSection) {
targetSection.classList.remove('hidden');
console.log('Section shown:', sectionName);
} else {
console.error('Section not found:', sectionName);
console.log('Available sections:', document.querySelectorAll('.admin-section'));
return;
}
// Update navigation - reset all items to default state
document.querySelectorAll('.nav-link').forEach(item => {
// Remove active classes
item.classList.remove('active', 'bg-red-cross-blue', 'text-white');
// Add default classes
item.classList.add('bg-red-cross-light-blue', 'text-gray-800');
});
// Add active state to current section
const activeItem = document.querySelector(`[data-section="${sectionName}"]`);
if (activeItem) {
// Remove default classes
activeItem.classList.remove('bg-red-cross-light-blue', 'text-gray-800');
// Add active classes
activeItem.classList.add('active', 'bg-red-cross-blue', 'text-white');
console.log('Navigation updated for:', sectionName);
} else {
console.error('Navigation item not found for:', sectionName);
}
currentSection = sectionName;
}
// Setup profile menu
function setupProfileMenu() {
console.log('Setting up profile menu...');
// Use a more direct approach with inline onclick
const profileMenuBtn = document.getElementById('profileMenuBtn');
const profileMenu = document.getElementById('profileMenu');
if (!profileMenuBtn || !profileMenu) {
console.error('Profile menu elements not found!');
return;
}
// Add onclick directly to the button
profileMenuBtn.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
console.log('Profile menu clicked');
profileMenu.classList.toggle('hidden');
};
// Close menu when clicking outside
document.addEventListener('click', function(e) {
if (!profileMenuBtn.contains(e.target) && !profileMenu.contains(e.target)) {
profileMenu.classList.add('hidden');
}
});
console.log('Profile menu setup complete');
}
// Toggle profile menu function
function toggleProfileMenu() {
console.log('Toggling profile menu...');
const profileMenu = document.getElementById('profileMenu');
if (profileMenu) {
profileMenu.classList.toggle('hidden');
console.log('Profile menu toggled');
// Add click outside handler
if (!profileMenu.classList.contains('hidden')) {
setTimeout(() => {
document.addEventListener('click', function closeProfileMenu(e) {
if (!e.target.closest('#profileMenuBtn') && !e.target.closest('#profileMenu')) {
profileMenu.classList.add('hidden');
document.removeEventListener('click', closeProfileMenu);
}
});
}, 100);
}
} else {
console.error('Profile menu not found!');
}
}
// Logout function
function logout() {
console.log('Logging out...');
// Clear any stored session data
localStorage.removeItem('adminLoggedIn');
localStorage.removeItem('adminUser');
localStorage.removeItem('userLoggedIn');
localStorage.removeItem('user');
// Redirect to main site
window.location.href = 'index.html';
}
// Setup modals
function setupModals() {
// Close modals when clicking outside
document.querySelectorAll('.modal').forEach(modal => {
modal.addEventListener('click', function(e) {
if (e.target === this) {
this.classList.add('hidden');
}
});
});
}
// Open modal
function openModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
}
// Close modal
function closeModal(modalId) {
document.getElementById(modalId).classList.add('hidden');
// Reset form
document.querySelector(`#${modalId} form`).reset();
}
// Setup search and filters
function setupSearchAndFilters() {
// User search and filters
const userSearch = document.getElementById('userSearch');
const userRoleFilter = document.getElementById('userRoleFilter');
const userStatusFilter = document.getElementById('userStatusFilter');
[userSearch, userRoleFilter, userStatusFilter].forEach(element => {
element.addEventListener('input', filterUsers);
});
// Event search and filters
const eventSearch = document.getElementById('eventSearch');
const eventStatusFilter = document.getElementById('eventStatusFilter');
[eventSearch, eventStatusFilter].forEach(element => {
element.addEventListener('input', filterEvents);
});
// Volunteer search and filters
const volunteerSearch = document.getElementById('volunteerSearch');
const volunteerStatusFilter = document.getElementById('volunteerStatusFilter');
[volunteerSearch, volunteerStatusFilter].forEach(element => {
element.addEventListener('input', filterVolunteers);
});
}
// Filter users
function filterUsers() {
const searchTerm = document.getElementById('userSearch').value.toLowerCase();
const roleFilter = document.getElementById('userRoleFilter').value;
const statusFilter = document.getElementById('userStatusFilter').value;
filteredUsers = sampleUsers.filter(user => {
const matchesSearch = user.name.toLowerCase().includes(searchTerm) ||
user.email.toLowerCase().includes(searchTerm);
const matchesRole = !roleFilter || user.role === roleFilter;
const matchesStatus = !statusFilter || user.status === statusFilter;
return matchesSearch && matchesRole && matchesStatus;
});
loadUsersData();
}
// Filter events
function filterEvents() {
const searchTerm = document.getElementById('eventSearch').value.toLowerCase();
const statusFilter = document.getElementById('eventStatusFilter').value;
filteredEvents = sampleEvents.filter(event => {
const matchesSearch = event.title.toLowerCase().includes(searchTerm) ||
event.description.toLowerCase().includes(searchTerm);
const matchesStatus = !statusFilter || event.status === statusFilter;
return matchesSearch && matchesStatus;
});
loadEventsData();
}
// Filter volunteers
function filterVolunteers() {
const searchTerm = document.getElementById('volunteerSearch').value.toLowerCase();
const statusFilter = document.getElementById('volunteerStatusFilter').value;
filteredVolunteers = sampleVolunteers.filter(volunteer => {
const matchesSearch = volunteer.name.toLowerCase().includes(searchTerm) ||
volunteer.email.toLowerCase().includes(searchTerm);
const matchesStatus = !statusFilter || volunteer.status === statusFilter;
return matchesSearch && matchesStatus;
});
loadVolunteersData();
}
// Load dashboard data
function loadDashboardData() {
// Dashboard data is already loaded in HTML
// This function can be used to update real-time data
updateDashboardStats();
}
// Update dashboard stats
function updateDashboardStats() {
// This would typically fetch real data from an API
// For now, we'll use the sample data
const totalUsers = sampleUsers.length;
const activeVolunteers = sampleVolunteers.filter(v => v.status === 'active').length;
const upcomingEvents = sampleEvents.filter(e => e.status === 'upcoming').length;
const totalDonations = sampleDonations.reduce((sum, d) => sum + d.amount, 0);
// Update stats in the UI (if needed)
console.log('Dashboard stats updated:', {
totalUsers,
activeVolunteers,
upcomingEvents,
totalDonations
});
}
// Load users data
function loadUsersData() {
const tbody = document.getElementById('usersTableBody');
tbody.innerHTML = '';
filteredUsers.forEach(user => {
const row = createUserRow(user);
tbody.appendChild(row);
});
}
// Create user row
function createUserRow(user) {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="w-10 h-10 bg-red-cross-blue rounded-full flex items-center justify-center text-white font-semibold">
${user.avatar}
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">${user.name}</div>
<div class="text-sm text-gray-500">${user.email}</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getRoleBadgeClass(user.role)}">
${user.role.charAt(0).toUpperCase() + user.role.slice(1)}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getStatusBadgeClass(user.status)}">
${user.status.charAt(0).toUpperCase() + user.status.slice(1)}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
${user.lastActive}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<div class="flex space-x-2">
<button onclick="editUser(${user.id})" class="text-red-cross-blue hover:text-red-cross-secondary-blue">
<i class="fas fa-edit"></i>
</button>
<button onclick="toggleUserStatus(${user.id})" class="text-yellow-600 hover:text-yellow-700">
<i class="fas fa-toggle-${user.status === 'active' ? 'on' : 'off'}"></i>
</button>
<button onclick="deleteUser(${user.id})" class="text-red-600 hover:text-red-700">
<i class="fas fa-trash"></i>
</button>
</div>
</td>
`;
return row;
}
// Load events data
function loadEventsData() {
const eventsGrid = document.getElementById('eventsGrid');
eventsGrid.innerHTML = '';
filteredEvents.forEach(event => {
const eventCard = createEventCard(event);
eventsGrid.appendChild(eventCard);
});
}
// Create event card
function createEventCard(event) {
const card = document.createElement('div');
card.className = 'bg-white rounded-lg shadow-lg p-6';
card.innerHTML = `
<div class="flex justify-between items-start mb-4">
<h3 class="text-lg font-semibold text-gray-800">${event.title}</h3>
<span class="px-2 py-1 text-xs font-semibold rounded-full ${getStatusBadgeClass(event.status)}">
${event.status.charAt(0).toUpperCase() + event.status.slice(1)}
</span>
</div>
<div class="space-y-2 mb-4">
<div class="flex items-center text-sm text-gray-600">
<i class="fas fa-calendar mr-2"></i>
${new Date(event.date).toLocaleDateString()}
</div>
<div class="flex items-center text-sm text-gray-600">
<i class="fas fa-map-marker-alt mr-2"></i>
${event.location}
</div>
<div class="flex items-center text-sm text-gray-600">
<i class="fas fa-users mr-2"></i>
${event.volunteers} volunteers
</div>
</div>
<p class="text-sm text-gray-600 mb-4">${event.description}</p>
<div class="flex space-x-2">
<button onclick="editEvent(${event.id})" class="flex-1 bg-red-cross-blue text-white px-3 py-2 rounded text-sm hover:bg-red-cross-secondary-blue transition-colors">
<i class="fas fa-edit mr-1"></i>Edit
</button>
<button onclick="deleteEvent(${event.id})" class="px-3 py-2 border border-red-600 text-red-600 rounded text-sm hover:bg-red-600 hover:text-white transition-colors">
<i class="fas fa-trash"></i>
</button>
</div>
`;
return card;
}
// Load volunteers data
function loadVolunteersData() {
const tbody = document.getElementById('volunteersTableBody');
tbody.innerHTML = '';
filteredVolunteers.forEach(volunteer => {
const row = createVolunteerRow(volunteer);
tbody.appendChild(row);
});
}
// Create volunteer row
function createVolunteerRow(volunteer) {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="w-10 h-10 bg-green-500 rounded-full flex items-center justify-center text-white font-semibold">
${volunteer.name.split(' ').map(n => n[0]).join('')}
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">${volunteer.name}</div>
<div class="text-sm text-gray-500">${volunteer.email}</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
${volunteer.role}
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getStatusBadgeClass(volunteer.status)}">
${volunteer.status.charAt(0).toUpperCase() + volunteer.status.slice(1)}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
${volunteer.tasks.join(', ')}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<div class="flex space-x-2">
<button onclick="editVolunteer(${volunteer.id})" class="text-red-cross-blue hover:text-red-cross-secondary-blue">
<i class="fas fa-edit"></i>
</button>
<button onclick="toggleVolunteerStatus(${volunteer.id})" class="text-yellow-600 hover:text-yellow-700">
<i class="fas fa-toggle-${volunteer.status === 'active' ? 'on' : 'off'}"></i>
</button>
<button onclick="deleteVolunteer(${volunteer.id})" class="text-red-600 hover:text-red-700">
<i class="fas fa-trash"></i>
</button>
</div>
</td>
`;
return row;
}
// Load donations data
function loadDonationsData() {
const tbody = document.getElementById('donationsTableBody');
tbody.innerHTML = '';
sampleDonations.forEach(donation => {
const row = createDonationRow(donation);
tbody.appendChild(row);
});
}
// Create donation row
function createDonationRow(donation) {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
${donation.donor}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
₱${donation.amount.toLocaleString()}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
${donation.method}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
${new Date(donation.date).toLocaleDateString()}
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getStatusBadgeClass(donation.status)}">
${donation.status.charAt(0).toUpperCase() + donation.status.slice(1)}
</span>
</td>
`;
return row;
}
// Utility functions
function getRoleBadgeClass(role) {
const classes = {
'admin': 'bg-red-100 text-red-800',
'staff': 'bg-blue-100 text-blue-800',
'volunteer': 'bg-green-100 text-green-800',
'member': 'bg-gray-100 text-gray-800'
};
return classes[role] || 'bg-gray-100 text-gray-800';
}
function getStatusBadgeClass(status) {
const classes = {
'active': 'bg-green-100 text-green-800',
'inactive': 'bg-red-100 text-red-800',
'pending': 'bg-yellow-100 text-yellow-800',
'completed': 'bg-blue-100 text-blue-800',
'cancelled': 'bg-gray-100 text-gray-800',
'upcoming': 'bg-blue-100 text-blue-800',
'ongoing': 'bg-yellow-100 text-yellow-800'
};
return classes[status] || 'bg-gray-100 text-gray-800';
}
// Event handlers
function handleEventSubmit(e) {
e.preventDefault();
const eventData = {
title: document.getElementById('eventTitle').value,
date: document.getElementById('eventDate').value,
location: document.getElementById('eventLocation').value,
description: document.getElementById('eventDescription').value,
status: document.getElementById('eventStatus').value
};
// Add new event to sample data
const newEvent = {
id: sampleEvents.length + 1,
...eventData,
volunteers: 0
};
sampleEvents.unshift(newEvent);
filteredEvents = [...sampleEvents];
loadEventsData();
closeModal('eventModal');
// Show success message
showNotification('Event created successfully!', 'success');
}
function handleUserSubmit(e) {
e.preventDefault();
const userData = {
firstName: document.getElementById('userFirstName').value,
lastName: document.getElementById('userLastName').value,
email: document.getElementById('userEmail').value,
role: document.getElementById('userRole').value,
status: document.getElementById('userStatus').value
};
// Add new user to sample data
const newUser = {
id: sampleUsers.length + 1,
name: `${userData.firstName} ${userData.lastName}`,
email: userData.email,
role: userData.role,
status: userData.status,
lastActive: new Date().toISOString().split('T')[0],
avatar: `${userData.firstName[0]}${userData.lastName[0]}`
};
sampleUsers.unshift(newUser);
filteredUsers = [...sampleUsers];
loadUsersData();
closeModal('userModal');
// Show success message
showNotification('User created successfully!', 'success');
}
// User actions
function editUser(userId) {
console.log('Editing user:', userId);
const user = sampleUsers.find(u => u.id === userId);
if (user) {
// Pre-fill form with user data