File size: 11,812 Bytes
3b92d5d a6c37c3 3b92d5d 06f4684 3b92d5d 06f4684 a6c37c3 3b92d5d 0dadafa a6c37c3 0dadafa a6c37c3 0dadafa | 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 |
// Shared functions
function initTooltips() {
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
tooltipTriggers.forEach(trigger => {
const tooltip = document.createElement('div');
tooltip.className = 'tooltip hidden absolute z-50 bg-gray-800 text-white text-xs rounded py-1 px-2';
tooltip.textContent = trigger.getAttribute('data-tooltip');
trigger.appendChild(tooltip);
trigger.addEventListener('mouseenter', () => {
tooltip.classList.remove('hidden');
});
trigger.addEventListener('mouseleave', () => {
tooltip.classList.add('hidden');
});
});
}
// Notification management
function updateNotificationCount(count) {
const notificationElements = document.querySelectorAll('notification-bell');
notificationElements.forEach(element => {
const countSpan = element.shadowRoot.getElementById('notificationCount');
if (countSpan) {
countSpan.textContent = count;
countSpan.style.display = count > 0 ? 'flex' : 'none';
}
});
}
// Initialize notifications
function initNotifications() {
const userData = JSON.parse(localStorage.getItem('currentUser'));
if (userData) {
// Simulate notification count
setTimeout(() => {
updateNotificationCount(2);
}, 1000);
}
}
// Admin Functions
function runAutoMatching() {
const users = JSON.parse(localStorage.getItem('users')) || [];
const matches = JSON.parse(localStorage.getItem('matches')) || [];
// Simple matching algorithm based on industry and experience
users.forEach(founder => {
if (founder.role === 'founder') {
users.forEach(advisor => {
if (advisor.role === 'advisor') {
let compatibilityScore = calculateCompatibility(founder, advisor);
if (compatibilityScore > 70) {
const newMatch = {
id: Date.now(),
founderId: founder.id,
advisorId: advisor.id,
compatibilityScore: compatibilityScore,
status: 'suggested',
created: new Date().toISOString(),
matchType: 'auto'
};
matches.push(newMatch);
}
}
});
});
localStorage.setItem('matches', JSON.stringify(matches));
alert(`Auto-matching completed! Found ${matches.length} potential matches.`);
}
function calculateCompatibility(founder, advisor) {
let score = 50; // Base score
// Industry match
if (founder.industry && advisor.industries && advisor.industries.includes(founder.industry)) {
score += 20;
}
// Experience level consideration
if (founder.businessStage === 'early' && advisor.yearsExperience === '1-3') {
score += 10;
}
// Add some randomness for human factor simulation
score += Math.random() * 20;
return Math.min(Math.round(score), 100);
}
function approveMatch(matchId) {
const matches = JSON.parse(localStorage.getItem('matches')) || [];
const matchIndex = matches.findIndex(m => m.id === matchId);
if (matchIndex !== -1) {
matches[matchIndex].status = 'approved';
matches[matchIndex].approvedBy = 'admin';
matches[matchIndex].approvedAt = new Date().toISOString();
localStorage.setItem('matches', JSON.stringify(matches));
// Log the approval
logAdminAction('match_approval', `Approved match ${matchId}`);
alert('Match approved successfully!');
}
}
function suggestManualMatch(founderId, advisorId) {
const matches = JSON.parse(localStorage.getItem('matches')) || [];
const newMatch = {
id: Date.now(),
founderId: founderId,
advisorId: advisorId,
compatibilityScore: 85, // High score for manual suggestions
status: 'suggested',
created: new Date().toISOString(),
matchType: 'manual'
};
matches.push(newMatch);
localStorage.setItem('matches', JSON.stringify(matches));
logAdminAction('manual_match_suggestion', `Suggested match between founder ${founderId} and advisor ${advisorId}`,
suggestedBy: 'admin'
};
localStorage.setItem('matches', JSON.stringify(matches));
alert('Manual match suggested successfully!');
}
function manageUserStatus(userId, status) {
const users = JSON.parse(localStorage.getItem('users')) || [];
const userIndex = users.findIndex(u => u.id === userId);
if (userIndex !== -1) {
users[userIndex].status = status;
users[userIndex].statusUpdatedAt = new Date().toISOString();
localStorage.setItem('users', JSON.stringify(users)));
logAdminAction('user_status_change', `Changed user ${userId} status to ${status}`);
alert(`User status updated to ${status}`);
}
function logAdminAction(action, description) {
const auditLog = JSON.parse(localStorage.getItem('auditLog')) || [];
const adminData = JSON.parse(localStorage.getItem('currentUser'));
const logEntry = {
id: Date.now(),
adminId: adminData.id,
action: action,
description: description,
timestamp: new Date().toISOString()
};
auditLog.push(logEntry);
localStorage.setItem('auditLog', JSON.stringify(auditLog)));
}
document.addEventListener('DOMContentLoaded', function() {
// Initialize all tooltips
initTooltips();
// Initialize notifications
initNotifications();
// Initialize dashboard data if on dashboard pages
if (window.location.pathname === '/admin-dashboard.html') {
const stats = getDashboardStats();
// Update admin dashboard stats
const statElements = document.querySelectorAll('.stat-value');
if (statElements.length >= 4) {
statElements[0].textContent = stats.totalUsers;
statElements[1].textContent = stats.founders;
statElements[2].textContent = stats.advisors;
statElements[3].textContent = `${Math.round((stats.activeMatches / (stats.activeMatches + stats.pendingMatches)) * 100)}%`;
}
}
// Animate elements on scroll
const animateOnScroll = () => {
const elements = document.querySelectorAll('.animate-on-scroll');
elements.forEach(el => {
const rect = el.getBoundingClientRect();
const isVisible = (rect.top <= window.innerHeight * 0.75) && (rect.bottom >= 0);
if (isVisible) {
el.classList.add('animate-fade-in');
}
});
};
window.addEventListener('scroll', animateOnScroll);
animateOnScroll(); // Run once on load
});
// Form validation helper
function validateForm(formId) {
const form = document.getElementById(formId);
if (!form) return true;
let isValid = true;
const inputs = form.querySelectorAll('input[required], select[required], textarea[required]');
inputs.forEach(input => {
if (!input.value.trim()) {
input.classList.add('border-red-500');
isValid = false;
} else {
input.classList.remove('border-red-500');
}
});
// Validate payment method selection
const paymentSelected = form.querySelector('.payment-method.border-blue-500, .payment-method.border-purple-500');
if (!paymentSelected) {
alert('Please select a payment method');
return false;
}
// Validate payment details
if (paymentSelected.textContent.includes('Card')) {
const cardNumber = form.querySelector('#cardNumber');
const cardExpiry = form.querySelector('#cardExpiry');
const cardCvv = form.querySelector('#cardCvv');
if (!cardNumber.value.trim() || !cardExpiry.value.trim() || !cardCvv.value.trim()) {
alert('Please complete all card payment details');
return false;
}
} else if (paymentSelected.textContent.includes('MTN') || paymentSelected.textContent.includes('Airtel')) {
const mobileNumber = form.querySelector('#mobileNumber');
if (!mobileNumber.value.trim()) {
alert('Please enter your mobile money number');
return false;
}
}
return isValid;
}
// Handle successful form submission
function handleFormSuccess(formType) {
// Store registration data in localStorage
const formData = new FormData(document.getElementById(formType === 'founder' ? 'founderForm' : 'advisorForm'));
const userData = Object.fromEntries(formData.entries());
// Generate unique ID and add role
userData.id = Date.now();
userData.role = formType;
userData.registrationDate = new Date().toISOString();
userData.status = 'active';
// Store in users array
const users = JSON.parse(localStorage.getItem('users')) || [];
users.push(userData);
localStorage.setItem('users', JSON.stringify(users));
localStorage.setItem('currentUser', JSON.stringify(userData));
// Simulate payment processing
setTimeout(() => {
window.location.href = '/dashboard.html';
}, 1500);
}
// Admin authentication
function authenticateAdmin(username, password) {
// Simple admin authentication (in production, use secure backend)
const adminCredentials = [
{ username: 'admin', password: 'admin123' },
{ username: 'supervisor', password: 'super123' }
];
const validAdmin = adminCredentials.find(admin =>
admin.username === username && admin.password === password
);
if (validAdmin) {
const adminData = {
id: Date.now(),
fullName: 'System Administrator',
username: username,
role: 'admin',
status: 'active',
loginTime: new Date().toISOString()
};
localStorage.setItem('currentUser', JSON.stringify(adminData));
return true;
}
return false;
}
// Dashboard data functions
function getDashboardStats() {
const users = JSON.parse(localStorage.getItem('users')) || [];
const matches = JSON.parse(localStorage.getItem('matches')) || [];
const totalUsers = users.length;
const founders = users.filter(u => u.role === 'founder').length;
const advisors = users.filter(u => u.role === 'advisor').length;
const activeMatches = matches.filter(m => m.status === 'active').length;
const pendingMatches = matches.filter(m => m.status === 'pending').length;
return {
totalUsers,
founders,
advisors,
activeMatches,
pendingMatches
};
}
// Get user activity data
function getUserActivity() {
const users = JSON.parse(localStorage.getItem('users')) || [];
// Sort by registration date
return users.sort((a, b) => new Date(b.registrationDate) - new Date(a.registrationDate)).slice(0, 5);
}
// Get recent matches
function getRecentMatches() {
const matches = JSON.parse(localStorage.getItem('matches')) || [];
// Sort by creation date
return matches.sort((a, b) => new Date(b.created) - new Date(a.created))).slice(0, 5);
}
|