Spaces:
Running
Running
make it also smartphone screen compatible, in that it can adjust - Follow Up Deployment
e9f8cc2 verified Download index.html from BizzareEmpire/cod-k: direct link, hf CLI and curl.
- Browser
- Download file 78.6 kB
-
https://huggingface.co/spaces/BizzareEmpire/cod-k/resolve/main/index.html
- Command line
-
hf download hf://spaces/BizzareEmpire/cod-k/index.html
-
curl -L -o index.html https://huggingface.co/spaces/BizzareEmpire/cod-k/resolve/main/index.html
78.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>CoD-K National Opinion Hub</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<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.25/jspdf.plugin.autotable.min.js"></script>
<style>
/* Mobile-specific styles */
@media (max-width: 640px) {
.map-container {
height: 300px;
}
.question-card {
padding: 0.75rem;
}
.page {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.survey-card {
margin-bottom: 0.75rem;
}
}
.question-card {
transition: all 0.3s ease;
}
.question-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.dragging {
opacity: 0.5;
background-color: #f0fdf4;
}
.map-container {
height: 400px;
background-color: #f0f0f0;
position: relative;
overflow: hidden;
}
.county-dot {
position: absolute;
width: 12px;
height: 12px;
background-color: #10b981;
border-radius: 50%;
transform: translate(-50%, -50%);
transition: all 0.3s ease;
}
.county-dot:hover {
width: 16px;
height: 16px;
background-color: #059669;
}
.county-tooltip {
position: absolute;
background-color: white;
padding: 5px 10px;
border-radius: 4px;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
font-size: 12px;
pointer-events: none;
z-index: 100;
}
.fade-in {
animation: fadeIn 0.5s;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
</style>
</head>
<body class="bg-gray-50">
<!-- Navigation -->
<nav class="bg-green-800 text-white shadow-lg">
<div class="container mx-auto px-4 py-3 flex justify-between items-center">
<div class="flex items-center space-x-2">
<div class="w-10 h-10 bg-white rounded-full flex items-center justify-center">
<span class="text-green-800 font-bold text-xl">CoD-K</span>
</div>
<h1 class="text-xl font-bold">National Opinion Hub</h1>
</div>
<div class="hidden md:flex space-x-6">
<a href="#" onclick="showPage('home')" class="hover:text-green-200">Home</a>
<a href="#" onclick="showPage('surveys')" class="hover:text-green-200">Surveys</a>
<a href="#" onclick="showPage('dashboard')" class="hover:text-green-200">Dashboard</a>
<a href="#" onclick="showPage('admin')" id="adminLink" class="hover:text-green-200 hidden">Admin</a>
</div>
<div class="md:hidden flex items-center">
<button id="mobileMenuButton" class="text-white focus:outline-none">
<i class="fas fa-bars text-2xl"></i>
</button>
</div>
</div>
<!-- Mobile menu -->
<div id="mobileMenu" class="hidden bg-green-700 md:hidden">
<div class="px-4 py-2 flex flex-col space-y-3">
<a href="#" onclick="showPage('home')" class="hover:text-green-200">Home</a>
<a href="#" onclick="showPage('surveys')" class="hover:text-green-200">Surveys</a>
<a href="#" onclick="showPage('dashboard')" class="hover:text-green-200">Dashboard</a>
<a href="#" onclick="showPage('admin')" id="mobileAdminLink" class="hover:text-green-200 hidden">Admin</a>
</div>
</div>
</nav>
<!-- Home Page -->
<div id="home" class="page container mx-auto px-2 sm:px-4 py-4 sm:py-8">
<div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
<div class="bg-green-700 text-white p-6">
<h2 class="text-3xl font-bold mb-2">Welcome to CoD-K National Opinion Hub</h2>
<p class="text-green-100">Your voice matters in shaping the future of Kenya. Participate in our surveys and make your opinion count.</p>
</div>
<div class="p-6">
<div class="grid md:grid-cols-2 gap-8">
<div>
<h3 class="text-2xl font-semibold mb-4 text-green-800">About CoD-K</h3>
<p class="text-gray-700 mb-4">Conservation of Democracy – Kenya (CoD-K) is a political movement led by George Natembeya, dedicated to preserving democratic values and ensuring the voices of all Kenyans are heard.</p>
<p class="text-gray-700">This platform allows us to gather national opinions on important issues affecting our country.</p>
</div>
<div>
<h3 class="text-2xl font-semibold mb-4 text-green-800">Current Surveys</h3>
<div id="featuredSurveys" class="space-y-4">
<!-- Featured surveys will be loaded here -->
</div>
</div>
</div>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 sm:gap-6 mb-6 sm:mb-8">
<div class="bg-white rounded-lg shadow-md p-6 hover:shadow-lg transition-shadow">
<div class="text-green-600 mb-4">
<i class="fas fa-vote-yea text-4xl"></i>
</div>
<h3 class="text-xl font-semibold mb-2">Participate</h3>
<p class="text-gray-600">Take part in our ongoing surveys and share your views on important national issues.</p>
</div>
<div class="bg-white rounded-lg shadow-md p-6 hover:shadow-lg transition-shadow">
<div class="text-green-600 mb-4">
<i class="fas fa-chart-bar text-4xl"></i>
</div>
<h3 class="text-xl font-semibold mb-2">See Results</h3>
<p class="text-gray-600">View summarized results and insights from completed surveys.</p>
</div>
<div class="bg-white rounded-lg shadow-md p-6 hover:shadow-lg transition-shadow">
<div class="text-green-600 mb-4">
<i class="fas fa-handshake text-4xl"></i>
</div>
<h3 class="text-xl font-semibold mb-2">Join the Movement</h3>
<p class="text-gray-600">Become part of the movement to conserve democracy in Kenya.</p>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h3 class="text-2xl font-semibold mb-4 text-green-800">Kenya's Democratic Journey</h3>
<div class="flex items-center mb-4">
<div class="w-1/4 h-2 bg-red-600"></div>
<div class="w-1/4 h-2 bg-black"></div>
<div class="w-1/4 h-2 bg-white border border-gray-300"></div>
<div class="w-1/4 h-2 bg-green-600"></div>
</div>
<p class="text-gray-700">Our national colors represent the blood shed for freedom (red), the people (black), peace (white), and our land (green). CoD-K is committed to upholding these values through inclusive governance and public participation.</p>
</div>
</div>
<!-- Surveys List Page -->
<div id="surveys" class="page container mx-auto px-4 py-8 hidden">
<div class="flex justify-between items-center mb-8">
<h2 class="text-2xl font-bold text-green-800">Available Surveys</h2>
<button id="createSurveyBtn" class="bg-green-700 hover:bg-green-800 text-white px-4 py-2 rounded-lg hidden">
<i class="fas fa-plus mr-2"></i>Create Survey
</button>
</div>
<div id="surveyList" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
<!-- Surveys will be loaded here -->
</div>
</div>
<!-- Survey Builder Page -->
<div id="surveyBuilder" class="page container mx-auto px-4 py-8 hidden">
<div class="bg-white rounded-lg shadow-lg overflow-hidden mb-8">
<div class="bg-green-700 text-white p-4 flex justify-between items-center">
<h2 class="text-xl font-bold">Survey Builder</h2>
<div>
<button id="saveSurveyBtn" class="bg-white text-green-700 px-4 py-1 rounded mr-2">
<i class="fas fa-save mr-1"></i>Save
</button>
<button onclick="showPage('surveys')" class="bg-red-500 text-white px-4 py-1 rounded">
<i class="fas fa-times mr-1"></i>Cancel
</button>
</div>
</div>
<div class="p-6">
<div class="mb-6">
<label class="block text-gray-700 font-medium mb-2">Survey Title</label>
<input type="text" id="surveyTitle" class="w-full px-3 py-2 sm:px-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" placeholder="Enter survey title">
</div>
<div class="mb-6">
<label class="block text-gray-700 font-medium mb-2">Survey Description</label>
<textarea id="surveyDescription" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" rows="3" placeholder="Enter survey description"></textarea>
</div>
<div class="grid md:grid-cols-2 gap-4 mb-6">
<div>
<label class="block text-gray-700 font-medium mb-2">Survey Type</label>
<select id="surveyType" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500">
<option value="public">Public</option>
<option value="private">Private</option>
</select>
</div>
<div>
<label class="block text-gray-700 font-medium mb-2">Expiry Date (optional)</label>
<input type="date" id="surveyExpiry" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500">
</div>
</div>
<div class="mb-6">
<label class="block text-gray-700 font-medium mb-2">Maximum Responses (optional)</label>
<input type="number" id="surveyMaxResponses" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" placeholder="Leave blank for unlimited">
</div>
<hr class="my-6 border-gray-200">
<h3 class="text-xl font-semibold mb-4 text-green-800">Survey Questions</h3>
<div id="questionsContainer" class="space-y-4">
<!-- Questions will be added here -->
</div>
<div class="mt-6">
<button id="addQuestionBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg">
<i class="fas fa-plus mr-2"></i>Add Question
</button>
</div>
</div>
</div>
</div>
<!-- Take Survey Page -->
<div id="takeSurvey" class="page container mx-auto px-4 py-8 hidden">
<div class="bg-white rounded-lg shadow-lg overflow-hidden max-w-3xl mx-auto">
<div class="bg-green-700 text-white p-6">
<h2 id="surveyDisplayTitle" class="text-2xl font-bold mb-2"></h2>
<p id="surveyDisplayDescription" class="text-green-100"></p>
</div>
<div class="p-6">
<form id="surveyForm">
<div id="surveyQuestionsContainer" class="space-y-6">
<!-- Survey questions will be loaded here -->
</div>
<div class="mt-8">
<button type="submit" class="w-full bg-green-600 hover:bg-green-700 text-white py-3 px-6 rounded-lg font-medium">
Submit Survey
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Thank You Page -->
<div id="thankYou" class="page container mx-auto px-4 py-8 hidden">
<div class="bg-white rounded-lg shadow-lg overflow-hidden max-w-2xl mx-auto text-center p-12">
<div class="text-green-600 mb-6">
<i class="fas fa-check-circle text-6xl"></i>
</div>
<h2 class="text-3xl font-bold text-green-800 mb-4">Thank You!</h2>
<p class="text-gray-700 text-lg mb-6">Your response has been recorded. Your opinion matters in shaping the future of Kenya.</p>
<div class="flex justify-center">
<button onclick="showPage('home')" class="bg-green-600 hover:bg-green-700 text-white px-6 py-2 rounded-lg">
Return to Home
</button>
</div>
</div>
</div>
<!-- Dashboard Page -->
<div id="dashboard" class="page container mx-auto px-4 py-8 hidden">
<h2 class="text-2xl font-bold text-green-800 mb-6">Survey Dashboard</h2>
<div class="grid grid-cols-2 sm:grid-cols-4 gap-3 sm:gap-6 mb-6 sm:mb-8">
<div class="bg-white rounded-lg shadow-md p-6">
<div class="flex items-center">
<div class="p-3 rounded-full bg-green-100 text-green-700 mr-4">
<i class="fas fa-poll-h text-xl"></i>
</div>
<div>
<p class="text-gray-500">Total Surveys</p>
<h3 id="totalSurveys" class="text-2xl font-bold">0</h3>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<div class="flex items-center">
<div class="p-3 rounded-full bg-blue-100 text-blue-700 mr-4">
<i class="fas fa-users text-xl"></i>
</div>
<div>
<p class="text-gray-500">Total Responses</p>
<h3 id="totalResponses" class="text-2xl font-bold">0</h3>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<div class="flex items-center">
<div class="p-3 rounded-full bg-yellow-100 text-yellow-700 mr-4">
<i class="fas fa-spinner text-xl"></i>
</div>
<div>
<p class="text-gray-500">Active Surveys</p>
<h3 id="activeSurveys" class="text-2xl font-bold">0</h3>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<div class="flex items-center">
<div class="p-3 rounded-full bg-red-100 text-red-700 mr-4">
<i class="fas fa-check-circle text-xl"></i>
</div>
<div>
<p class="text-gray-500">Completed Surveys</p>
<h3 id="completedSurveys" class="text-2xl font-bold">0</h3>
</div>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-semibold text-green-800">Recent Survey Activity</h3>
<div class="flex space-x-2">
<select id="timeFilter" class="px-3 py-1 border rounded-lg">
<option value="7">Last 7 days</option>
<option value="30">Last 30 days</option>
<option value="90">Last 90 days</option>
<option value="all">All time</option>
</select>
</div>
</div>
<div class="h-64">
<canvas id="responseChart"></canvas>
</div>
</div>
<div class="grid lg:grid-cols-2 gap-6 mb-8">
<div class="bg-white rounded-lg shadow-md p-6">
<h3 class="text-xl font-semibold text-green-800 mb-4">Response Map</h3>
<div class="map-container relative">
<div id="kenyaMap"></div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h3 class="text-xl font-semibold text-green-800 mb-4">Top Surveys</h3>
<div id="topSurveys" class="space-y-4">
<!-- Top surveys will be loaded here -->
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h3 class="text-xl font-semibold text-green-800 mb-4">All Surveys</h3>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Title</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Responses</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Created</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="surveyTableBody" class="bg-white divide-y divide-gray-200">
<!-- Survey data will be loaded here -->
</tbody>
</table>
</div>
</div>
</div>
<!-- Responses Page -->
<div id="responses" class="page container mx-auto px-4 py-8 hidden">
<div class="flex justify-between items-center mb-6">
<h2 id="responsesSurveyTitle" class="text-2xl font-bold text-green-800"></h2>
<div class="flex flex-wrap gap-2">
<button id="exportCSV" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg text-sm">
<i class="fas fa-file-csv mr-1"></i>CSV
</button>
<button id="exportExcel" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg text-sm">
<i class="fas fa-file-excel mr-1"></i>Excel
</button>
<button id="exportPDF" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg text-sm">
<i class="fas fa-file-pdf mr-1"></i>PDF
</button>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold text-green-800">Response Summary</h3>
<div class="flex space-x-2">
<input type="text" id="responseSearch" placeholder="Search responses..." class="px-3 py-1 border rounded-lg">
<select id="responseFilter" class="px-3 py-1 border rounded-lg">
<option value="all">All responses</option>
<option value="today">Today</option>
<option value="week">This week</option>
<option value="month">This month</option>
</select>
</div>
</div>
<div class="grid md:grid-cols-2 gap-6 mb-6">
<div>
<h4 class="font-medium text-gray-700 mb-2">Response Rate</h4>
<div class="h-48">
<canvas id="responseRateChart"></canvas>
</div>
</div>
<div>
<h4 class="font-medium text-gray-700 mb-2">County Distribution</h4>
<div class="h-48">
<canvas id="countyChart"></canvas>
</div>
</div>
</div>
<div id="questionCharts" class="space-y-8">
<!-- Question charts will be loaded here -->
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h3 class="text-lg font-semibold text-green-800 mb-4">All Responses</h3>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">County</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="responsesTableBody" class="bg-white divide-y divide-gray-200">
<!-- Responses will be loaded here -->
</tbody>
</table>
</div>
</div>
</div>
<!-- Admin Login Page -->
<div id="admin" class="page container mx-auto px-4 py-8 max-w-md hidden">
<div class="bg-white rounded-lg shadow-lg overflow-hidden">
<div class="bg-green-700 text-white p-6 text-center">
<h2 class="text-2xl font-bold">Admin Login</h2>
<p class="text-green-100">Access the survey administration panel</p>
</div>
<div class="p-6">
<form id="adminLoginForm">
<div class="mb-4">
<label class="block text-gray-700 font-medium mb-2">Email</label>
<input type="email" id="adminEmail" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" placeholder="Enter your email" required>
</div>
<div class="mb-6">
<label class="block text-gray-700 font-medium mb-2">Password</label>
<input type="password" id="adminPassword" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" placeholder="Enter your password" required>
</div>
<div class="mb-4">
<button type="submit" class="w-full bg-green-600 hover:bg-green-700 text-white py-2 px-4 rounded-lg font-medium">
Login
</button>
</div>
<div class="text-center text-sm text-gray-600">
<p>Contact system administrator if you need access</p>
</div>
</form>
</div>
</div>
</div>
<!-- Question Type Modal -->
<div id="questionTypeModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-green-800">Select Question Type</h3>
</div>
<div class="p-2 sm:p-4 grid grid-cols-2 gap-2 sm:gap-4">
<button data-type="text" class="p-4 border rounded-lg hover:bg-green-50 flex flex-col items-center">
<i class="fas fa-font text-2xl text-green-600 mb-2"></i>
<span>Short Text</span>
</button>
<button data-type="textarea" class="p-4 border rounded-lg hover:bg-green-50 flex flex-col items-center">
<i class="fas fa-align-left text-2xl text-green-600 mb-2"></i>
<span>Long Text</span>
</button>
<button data-type="radio" class="p-4 border rounded-lg hover:bg-green-50 flex flex-col items-center">
<i class="fas fa-dot-circle text-2xl text-green-600 mb-2"></i>
<span>Multiple Choice</span>
</button>
<button data-type="checkbox" class="p-4 border rounded-lg hover:bg-green-50 flex flex-col items-center">
<i class="fas fa-check-square text-2xl text-green-600 mb-2"></i>
<span>Checkboxes</span>
</button>
<button data-type="select" class="p-4 border rounded-lg hover:bg-green-50 flex flex-col items-center">
<i class="fas fa-caret-down text-2xl text-green-600 mb-2"></i>
<span>Dropdown</span>
</button>
<button data-type="file" class="p-4 border rounded-lg hover:bg-green-50 flex flex-col items-center">
<i class="fas fa-file-upload text-2xl text-green-600 mb-2"></i>
<span>File Upload</span>
</button>
</div>
<div class="p-4 border-t flex justify-end">
<button id="cancelQuestionType" class="px-4 py-2 text-gray-600 hover:text-gray-800">
Cancel
</button>
</div>
</div>
</div>
<!-- View Response Modal -->
<div id="viewResponseModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="text-lg font-semibold text-green-800">Response Details</h3>
<button id="closeResponseModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="p-6">
<div id="responseDetails" class="space-y-4">
<!-- Response details will be loaded here -->
</div>
</div>
<div class="p-4 border-t flex justify-end">
<button onclick="hideModal('viewResponseModal')" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg">
Close
</button>
</div>
</div>
</div>
<!-- Duplicate Survey Modal -->
<div id="duplicateSurveyModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-green-800">Duplicate Survey</h3>
</div>
<div class="p-4">
<div class="mb-4">
<label class="block text-gray-700 font-medium mb-2">New Survey Title</label>
<input type="text" id="duplicateSurveyTitle" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" placeholder="Enter new title">
</div>
<div class="mb-4">
<label class="block text-gray-700 font-medium mb-2">Copy Responses?</label>
<select id="copyResponses" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500">
<option value="no">No, create empty survey</option>
<option value="yes">Yes, copy all responses</option>
</select>
</div>
</div>
<div class="p-4 border-t flex justify-end space-x-2">
<button onclick="hideModal('duplicateSurveyModal')" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg">
Cancel
</button>
<button id="confirmDuplicate" class="px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-lg">
Duplicate
</button>
</div>
</div>
</div>
<script>
// Initialize localStorage if not exists
if (!localStorage.getItem('codkSurveys')) {
localStorage.setItem('codkSurveys', JSON.stringify([]));
}
if (!localStorage.getItem('codkResponses')) {
localStorage.setItem('codkResponses', JSON.stringify([]));
}
if (!localStorage.getItem('codkAdmin')) {
localStorage.setItem('codkAdmin', JSON.stringify({
email: "admin@codk.org",
password: "CoD-K@2023" // In a real app, this would be hashed
}));
}
if (!localStorage.getItem('codkLoggedIn')) {
localStorage.setItem('codkLoggedIn', 'false');
}
// Sample counties in Kenya
const kenyaCounties = [
"Mombasa", "Kwale", "Kilifi", "Tana River", "Lamu", "Taita-Taveta", "Garissa", "Wajir", "Mandera",
"Marsabit", "Isiolo", "Meru", "Tharaka-Nithi", "Embu", "Kitui", "Machakos", "Makueni", "Nyandarua",
"Nyeri", "Kirinyaga", "Murang'a", "Kiambu", "Turkana", "West Pokot", "Samburu", "Trans-Nzoia",
"Uasin Gishu", "Elgeyo-Marakwet", "Nandi", "Baringo", "Laikipia", "Nakuru", "Narok", "Kajiado",
"Kericho", "Bomet", "Kakamega", "Vihiga", "Bungoma", "Busia", "Siaya", "Kisumu", "Homa Bay",
"Migori", "Kisii", "Nyamira", "Nairobi"
];
// Kenyan county coordinates for the map (simplified)
const countyCoordinates = {
"Mombasa": { x: 85, y: 25 },
"Nairobi": { x: 50, y: 50 },
"Kisumu": { x: 30, y: 70 },
"Nakuru": { x: 40, y: 60 },
"Eldoret": { x: 45, y: 65 },
"Machakos": { x: 55, y: 55 },
"Meru": { x: 65, y: 45 },
"Kakamega": { x: 25, y: 65 },
"Nyeri": { x: 50, y: 45 },
"Garissa": { x: 80, y: 40 },
"Kisii": { x: 35, y: 75 },
"Kericho": { x: 35, y: 60 },
"Bungoma": { x: 20, y: 60 },
"Malindi": { x: 90, y: 30 },
"Thika": { x: 55, y: 50 }
};
// Current state
let currentSurveyId = null;
let currentResponseId = null;
let currentEditingQuestionId = null;
let currentSurveyToDuplicate = null;
// DOM elements
const mobileMenuButton = document.getElementById('mobileMenuButton');
const mobileMenu = document.getElementById('mobileMenu');
// Event listeners
mobileMenuButton.addEventListener('click', () => {
mobileMenu.classList.toggle('hidden');
});
document.addEventListener('DOMContentLoaded', () => {
checkLoginStatus();
loadFeaturedSurveys();
loadSurveyList();
loadDashboardData();
// Initialize charts
initResponseChart();
initResponseRateChart();
initCountyChart();
// Initialize Kenya map
initKenyaMap();
// Set up event listeners for builder
setupSurveyBuilder();
// Set up admin login form
document.getElementById('adminLoginForm').addEventListener('submit', handleAdminLogin);
// Set up export buttons
document.getElementById('exportCSV').addEventListener('click', exportToCSV);
document.getElementById('exportExcel').addEventListener('click', exportToExcel);
document.getElementById('exportPDF').addEventListener('click', exportToPDF);
// Time filter change
document.getElementById('timeFilter').addEventListener('change', loadDashboardData);
// Response search and filter
document.getElementById('responseSearch').addEventListener('input', filterResponses);
document.getElementById('responseFilter').addEventListener('change', filterResponses);
});
function checkLoginStatus() {
const isLoggedIn = localStorage.getItem('codkLoggedIn') === 'true';
if (isLoggedIn) {
document.getElementById('adminLink').classList.remove('hidden');
document.getElementById('mobileAdminLink').classList.remove('hidden');
document.getElementById('createSurveyBtn').classList.remove('hidden');
}
}
function showPage(pageId) {
// Hide all pages
document.querySelectorAll('.page').forEach(page => {
page.classList.add('hidden');
});
// Show the requested page
document.getElementById(pageId).classList.remove('hidden');
// Close mobile menu if open
mobileMenu.classList.add('hidden');
// Load data if needed
if (pageId === 'dashboard') {
loadDashboardData();
} else if (pageId === 'surveys') {
loadSurveyList();
} else if (pageId === 'responses' && currentSurveyId) {
loadSurveyResponses(currentSurveyId);
}
}
function hideModal(modalId) {
document.getElementById(modalId).classList.add('hidden');
}
function showModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
}
// Survey Builder Functions
function setupSurveyBuilder() {
const addQuestionBtn = document.getElementById('addQuestionBtn');
const saveSurveyBtn = document.getElementById('saveSurveyBtn');
const createSurveyBtn = document.getElementById('createSurveyBtn');
const questionTypeModal = document.getElementById('questionTypeModal');
const cancelQuestionType = document.getElementById('cancelQuestionType');
// Show question type modal when adding a new question
addQuestionBtn.addEventListener('click', () => {
showModal('questionTypeModal');
});
// Cancel question type selection
cancelQuestionType.addEventListener('click', () => {
hideModal('questionTypeModal');
});
// Handle question type selection
document.querySelectorAll('#questionTypeModal button[data-type]').forEach(button => {
button.addEventListener('click', (e) => {
const type = e.currentTarget.getAttribute('data-type');
addQuestionToBuilder(type);
hideModal('questionTypeModal');
});
});
// Save survey
saveSurveyBtn.addEventListener('click', saveSurvey);
// Create new survey
createSurveyBtn.addEventListener('click', () => {
currentSurveyId = null;
resetSurveyBuilder();
showPage('surveyBuilder');
});
}
function resetSurveyBuilder() {
document.getElementById('surveyTitle').value = '';
document.getElementById('surveyDescription').value = '';
document.getElementById('surveyType').value = 'public';
document.getElementById('surveyExpiry').value = '';
document.getElementById('surveyMaxResponses').value = '';
const questionsContainer = document.getElementById('questionsContainer');
questionsContainer.innerHTML = '';
}
function addQuestionToBuilder(type) {
const questionId = Date.now().toString();
let questionHtml = '';
const questionTypes = {
'text': 'Short Text',
'textarea': 'Long Text',
'radio': 'Multiple Choice',
'checkbox': 'Checkboxes',
'select': 'Dropdown',
'file': 'File Upload'
};
// Common question structure
questionHtml = `
<div id="question-${questionId}" class="question-card bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
<div class="flex justify-between items-start mb-3">
<div class="flex items-center">
<span class="handle cursor-move mr-2 text-gray-400">
<i class="fas fa-grip-vertical"></i>
</span>
<h4 class="font-medium">${questionTypes[type]} Question</h4>
</div>
<div class="flex space-x-2">
<button onclick="editQuestion('${questionId}')" class="text-blue-600 hover:text-blue-800">
<i class="fas fa-edit"></i>
</button>
<button onclick="deleteQuestion('${questionId}')" class="text-red-600 hover:text-red-800">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
<div class="mb-3">
<input type="text" id="question-text-${questionId}" class="w-full px-3 py-2 border rounded-lg" placeholder="Enter question text">
</div>
<div class="mb-3">
<label class="flex items-center">
<input type="checkbox" id="question-required-${questionId}" class="mr-2">
<span class="text-sm text-gray-700">Required</span>
</label>
</div>
`;
// Add specific fields based on question type
switch (type) {
case 'radio':
case 'checkbox':
questionHtml += `
<div class="options-container mb-3" id="options-container-${questionId}">
<div class="option-item mb-2 flex items-center">
<input type="text" class="option-input w-full px-3 py-1 border rounded-lg mr-2" placeholder="Option text">
<button class="remove-option text-red-500 hover:text-red-700">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<button onclick="addOption('${questionId}')" class="text-sm text-green-600 hover:text-green-800 mb-3">
<i class="fas fa-plus mr-1"></i>Add Option
</button>
`;
break;
case 'select':
questionHtml += `
<div class="options-container mb-3" id="options-container-${questionId}">
<div class="option-item mb-2 flex items-center">
<input type="text" class="option-input w-full px-3 py-1 border rounded-lg mr-2" placeholder="Option text">
<button class="remove-option text-red-500 hover:text-red-700">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<button onclick="addOption('${questionId}')" class="text-sm text-green-600 hover:text-green-800 mb-3">
<i class="fas fa-plus mr-1"></i>Add Option
</button>
`;
break;
case 'file':
questionHtml += `
<div class="mb-3">
<select id="question-filetype-${questionId}" class="w-full px-3 py-2 border rounded-lg">
<option value="any">Any file type</option>
<option value="image">Image only</option>
<option value="pdf">PDF only</option>
<option value="document">Document (PDF, Word)</option>
</select>
</div>
`;
break;
}
// Add logic jump if not first question
const questionsContainer = document.getElementById('questionsContainer');
if (questionsContainer.children.length > 0) {
questionHtml += `
<div class="mb-3">
<label class="block text-sm font-medium text-gray-700 mb-1">Logic Jump</label>
<select id="question-logic-${questionId}" class="w-full px-3 py-2 border rounded-lg">
<option value="">No logic (continue to next question)</option>
<option value="end">End survey after this question</option>
</select>
</div>
`;
}
questionHtml += `
<input type="hidden" id="question-type-${questionId}" value="${type}">
</div>
`;
// Add question to container
questionsContainer.insertAdjacentHTML('beforeend', questionHtml);
// Make question draggable
makeQuestionDraggable(`question-${questionId}`);
}
function makeQuestionDraggable(questionId) {
const questionElement = document.getElementById(questionId);
const handle = questionElement.querySelector('.handle');
handle.addEventListener('mousedown', (e) => {
e.preventDefault();
const container = document.getElementById('questionsContainer');
const questions = Array.from(container.children);
const currentQuestion = document.getElementById(questionId);
const currentIndex = questions.indexOf(currentQuestion);
// Set placeholder
const placeholder = document.createElement('div');
placeholder.className = 'h-16 border-2 border-dashed border-green-500 my-2';
// Set dragging style
currentQuestion.classList.add('dragging');
// Clone the question for dragging visual
const clone = currentQuestion.cloneNode(true);
clone.style.position = 'absolute';
clone.style.width = `${currentQuestion.offsetWidth}px`;
clone.style.zIndex = '1000';
clone.style.opacity = '0.8';
clone.style.pointerEvents = 'none';
clone.style.transform = 'rotate(2deg)';
document.body.appendChild(clone);
// Mouse move handler
function onMouseMove(e) {
clone.style.left = `${e.pageX - clone.offsetWidth / 2}px`;
clone.style.top = `${e.pageY - 20}px`;
// Check if we're over another question
const elements = document.elementsFromPoint(e.clientX, e.clientY);
const overQuestion = elements.find(el => el.classList && el.classList.contains('question-card'));
if (overQuestion && overQuestion.id !== questionId) {
const overIndex = questions.indexOf(overQuestion);
if (overIndex !== -1) {
// Move placeholder to the correct position
if (e.pageY < overQuestion.getBoundingClientRect().top + overQuestion.offsetHeight / 2) {
// Insert before
container.insertBefore(placeholder, overQuestion);
} else {
// Insert after
if (overQuestion.nextSibling) {
container.insertBefore(placeholder, overQuestion.nextSibling);
} else {
container.appendChild(placeholder);
}
}
}
}
}
// Mouse up handler
function onMouseUp() {
// Remove clone
document.body.removeChild(clone);
currentQuestion.classList.remove('dragging');
// Get new position
const placeholderIndex = Array.from(container.children).indexOf(placeholder);
if (placeholderIndex !== -1 && placeholderIndex !== currentIndex) {
// Remove placeholder
container.removeChild(placeholder);
// Move question to new position
if (placeholderIndex < currentIndex) {
container.insertBefore(currentQuestion, container.children[placeholderIndex]);
} else {
if (container.children[placeholderIndex]) {
container.insertBefore(currentQuestion, container.children[placeholderIndex]);
} else {
container.appendChild(currentQuestion);
}
}
} else {
// Remove placeholder if not moved
if (placeholder.parentNode) {
container.removeChild(placeholder);
}
}
// Remove event listeners
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
}
// Add event listeners
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
});
}
function addOption(questionId) {
const optionsContainer = document.getElementById(`options-container-${questionId}`);
const optionHtml = `
<div class="option-item mb-2 flex items-center">
<input type="text" class="option-input w-full px-3 py-1 border rounded-lg mr-2" placeholder="Option text">
<button class="remove-option text-red-500 hover:text-red-700">
<i class="fas fa-times"></i>
</button>
</div>
`;
optionsContainer.insertAdjacentHTML('beforeend', optionHtml);
// Add event listener to remove button
const newOption = optionsContainer.lastElementChild;
const removeBtn = newOption.querySelector('.remove-option');
removeBtn.addEventListener('click', () => {
optionsContainer.removeChild(newOption);
});
}
function editQuestion(questionId) {
// In this simple implementation, editing is the same as adding new
// In a more advanced version, we would populate the question type modal with existing values
currentEditingQuestionId = questionId;
showModal('questionTypeModal');
}
function deleteQuestion(questionId) {
if (confirm('Are you sure you want to delete this question?')) {
const questionElement = document.getElementById(`question-${questionId}`);
questionElement.parentNode.removeChild(questionElement);
}
}
function saveSurvey() {
const title = document.getElementById('surveyTitle').value.trim();
const description = document.getElementById('surveyDescription').value.trim();
const type = document.getElementById('surveyType').value;
const expiry = document.getElementById('surveyExpiry').value;
const maxResponses = document.getElementById('surveyMaxResponses').value;
if (!title) {
alert('Please enter a survey title');
return;
}
// Get all questions
const questions = [];
const questionElements = document.getElementById('questionsContainer').children;
for (let i = 0; i < questionElements.length; i++) {
const questionElement = questionElements[i];
const questionId = questionElement.id.replace('question-', '');
const question = {
id: questionId,
text: document.getElementById(`question-text-${questionId}`).value.trim(),
type: document.getElementById(`question-type-${questionId}`).value,
required: document.getElementById(`question-required-${questionId}`).checked,
order: i + 1
};
// Add options for relevant question types
if (['radio', 'checkbox', 'select'].includes(question.type)) {
question.options = [];
const optionElements = document.getElementById(`options-container-${questionId}`).children;
for (let j = 0; j < optionElements.length; j++) {
const optionInput = optionElements[j].querySelector('.option-input');
question.options.push(optionInput.value.trim());
}
}
// Add file type if file upload
if (question.type === 'file') {
question.fileType = document.getElementById(`question-filetype-${questionId}`).value;
}
// Add logic if set
const logicElement = document.getElementById(`question-logic-${questionId}`);
if (logicElement) {
question.logic = logicElement.value;
}
questions.push(question);
}
// Create survey object
const survey = {
id: currentSurveyId || Date.now().toString(),
title,
description,
type,
questions,
createdAt: new Date().toISOString(),
createdBy: 'admin'
};
// Add optional fields
if (expiry) survey.expiry = expiry;
if (maxResponses) survey.maxResponses = parseInt(maxResponses);
// Save to localStorage
const surveys = JSON.parse(localStorage.getItem('codkSurveys'));
if (currentSurveyId) {
// Update existing survey
const index = surveys.findIndex(s => s.id === currentSurveyId);
if (index !== -1) {
surveys[index] = survey;
}
} else {
// Add new survey
surveys.push(survey);
}
localStorage.setItem('codkSurveys', JSON.stringify(surveys));
alert('Survey saved successfully!');
showPage('surveys');
}
// Survey List Functions
function loadSurveyList() {
const surveys = JSON.parse(localStorage.getItem('codkSurveys'));
const surveyList = document.getElementById('surveyList');
surveyList.innerHTML = '';
if (surveys.length === 0) {
surveyList.innerHTML = `
<div class="col-span-3 text-center py-8">
<i class="fas fa-poll-h text-4xl text-gray-400 mb-4"></i>
<p class="text-gray-600">No surveys available yet.</p>
</div>
`;
return;
}
surveys.forEach(survey => {
const responseCount = getResponseCountForSurvey(survey.id);
const isActive = !survey.expiry || new Date(survey.expiry) > new Date();
const surveyCard = document.createElement('div');
surveyCard.className = 'bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition-shadow';
surveyCard.innerHTML = `
<div class="p-6">
<div class="flex justify-between items-start mb-2">
<h3 class="text-xl font-semibold text-green-800">${survey.title}</h3>
<span class="px-2 py-1 text-xs rounded-full ${isActive ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'}">
${isActive ? 'Active' : 'Closed'}
</span>
</div>
<p class="text-gray-600 mb-4 text-sm">${survey.description || 'No description'}</p>
<div class="flex justify-between items-center text-sm">
<span class="text-gray-500"><i class="fas fa-users mr-1"></i> ${responseCount} responses</span>
<span class="text-gray-500"><i class="fas fa-calendar-alt mr-1"></i> ${formatDate(survey.createdAt)}</span>
</div>
</div>
<div class="bg-gray-50 px-6 py-3 flex justify-between">
<button onclick="takeSurvey('${survey.id}')" class="text-green-600 hover:text-green-800 font-medium">
<i class="fas fa-play mr-1"></i> Take Survey
</button>
<div class="admin-actions hidden">
<button onclick="editSurvey('${survey.id}')" class="text-blue-600 hover:text-blue-800 mr-3">
<i class="fas fa-edit"></i>
</button>
<button onclick="viewResponses('${survey.id}')" class="text-purple-600 hover:text-purple-800 mr-3">
<i class="fas fa-chart-bar"></i>
</button>
<button onclick="duplicateSurveyPrompt('${survey.id}')" class="text-yellow-600 hover:text-yellow-800">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
`;
// Show admin actions if logged in
if (localStorage.getItem('codkLoggedIn') === 'true') {
surveyCard.querySelector('.admin-actions').classList.remove('hidden');
}
surveyList.appendChild(surveyCard);
});
}
function getResponseCountForSurvey(surveyId) {
const responses = JSON.parse(localStorage.getItem('codkResponses'));
return responses.filter(r => r.surveyId === surveyId).length;
}
function formatDate(dateString) {
const options = { year: 'numeric', month: 'short', day: 'numeric' };
return new Date(dateString).toLocaleDateString(undefined, options);
}
function takeSurvey(surveyId) {
currentSurveyId = surveyId;
const surveys = JSON.parse(localStorage.getItem('codkSurveys'));
const survey = surveys.find(s => s.id === surveyId);
if (!survey) {
alert('Survey not found');
return;
}
// Check if survey is expired
if (survey.expiry && new Date(survey.expiry) < new Date()) {
alert('This survey has expired and is no longer accepting responses.');
return;
}
// Check if max responses reached
if (survey.maxResponses) {
const responseCount = getResponseCountForSurvey(surveyId);
if (responseCount >= survey.maxResponses) {
alert('This survey has reached the maximum number of responses.');
return;
}
}
// Display survey
document.getElementById('surveyDisplayTitle').textContent = survey.title;
document.getElementById('surveyDisplayDescription').textContent = survey.description || '';
const questionsContainer = document.getElementById('surveyQuestionsContainer');
questionsContainer.innerHTML = '';
survey.questions.forEach((question, index) => {
const questionHtml = `
<div class="question-group bg-gray-50 p-4 rounded-lg">
<div class="mb-3">
<label class="block font-medium text-gray-700">
${index + 1}. ${question.text}
${question.required ? '<span class="text-red-500">*</span>' : ''}
</label>
</div>
<div class="question-input">
${renderQuestionInput(question)}
</div>
</div>
`;
questionsContainer.insertAdjacentHTML('beforeend', questionHtml);
});
// Set up form submission
document.getElementById('surveyForm').onsubmit = function(e) {
e.preventDefault();
submitSurvey(survey);
};
showPage('takeSurvey');
}
function renderQuestionInput(question) {
let html = '';
switch (question.type) {
case 'text':
html = `<input type="text" name="q-${question.id}" class="w-full px-3 py-2 border rounded-lg" ${question.required ? 'required' : ''}>`;
break;
case 'textarea':
html = `<textarea name="q-${question.id}" class="w-full px-3 py-2 border rounded-lg" rows="3" ${question.required ? 'required' : ''}></textarea>`;
break;
case 'radio':
html = '<div class="space-y-2">';
question.options.forEach((option, i) => {
html += `
<label class="flex items-center">
<input type="radio" name="q-${question.id}" value="${option}" class="mr-2" ${question.required ? 'required' : ''}>
${option}
</label>
`;
});
html += '</div>';
break;
case 'checkbox':
html = '<div class="space-y-2">';
question.options.forEach((option, i) => {
html += `
<label class="flex items-center">
<input type="checkbox" name="q-${question.id}[]" value="${option}" class="mr-2">
${option}
</label>
`;
});
html += '</div>';
break;
case 'select':
html = `<select name="q-${question.id}" class="w-full px-3 py-2 border rounded-lg" ${question.required ? 'required' : ''}>
<option value="">Select an option</option>`;
question.options.forEach(option => {
html += `<option value="${option}">${option}</option>`;
});
html += '</select>';
break;
case 'file':
html = `<input type="file" name="q-${question.id}" class="w-full px-3 py-2 border rounded-lg" ${question.required ? 'required' : ''}
accept="${getFileAcceptAttribute(question.fileType)}">`;
break;
}
return html;
}
function getFileAcceptAttribute(fileType) {
switch (fileType) {
case 'image': return 'image/*';
case 'pdf': return '.pdf';
case 'document': return '.pdf,.doc,.docx';
default: return '*';
}
}
function submitSurvey(survey) {
const form = document.getElementById('surveyForm');
const formData = new FormData(form);
const responses = [];
// Convert FormData to object
const formValues = {};
for (let [key, value] of formData.entries()) {
formValues[key] = value;
}
// Get county (simulated for demo)
const county = kenyaCounties[Math.floor(Math.random() * kenyaCounties.length)];
// Create response object
const response = {
id: Date.now().toString(),
surveyId: survey.id,
county,
submittedAt: new Date().toISOString(),
answers: []
};
// Process each question
survey.questions.forEach(question => {
const answer = {
questionId: question.id,
questionText: question.text,
type: question.type
};
const formKey = `q-${question.id}`;
if (question.type === 'checkbox') {
// Checkboxes can have multiple values
answer.value = formData.getAll(formKey + '[]');
} else {
answer.value = formValues[formKey];
}
response.answers.push(answer);
});
// Save response
const allResponses = JSON.parse(localStorage.getItem('codkResponses'));
allResponses.push(response);
localStorage.setItem('codkResponses', JSON.stringify(allResponses));
// Show thank you page
showPage('thankYou');
}
function editSurvey(surveyId) {
currentSurveyId = surveyId;
const surveys = JSON.parse(localStorage.getItem('codkSurveys'));
const survey = surveys.find(s => s.id === surveyId);
if (!survey) {
alert('Survey not found');
return;
}
// Populate survey info
document.getElementById('surveyTitle').value = survey.title;
document.getElementById('surveyDescription').value = survey.description || '';
document.getElementById('surveyType').value = survey.type || 'public';
if (survey.expiry) {
document.getElementById('surveyExpiry').value = survey.expiry.split('T')[0];
}
if (survey.maxResponses) {
document.getElementById('surveyMaxResponses').value = survey.maxResponses;
}
// Clear existing questions
const questionsContainer = document.getElementById('questionsContainer');
questionsContainer.innerHTML = '';
// Add questions in order
const orderedQuestions = [...survey.questions].sort((a, b) => a.order - b.order);
orderedQuestions.forEach(question => {
const questionId = question.id;
// Create question element
const questionElement = document.createElement('div');
questionElement.id = `question-${questionId}`;
questionElement.className = 'question-card bg-white border border-gray-200 rounded-lg p-4 shadow-sm mb-4';
let questionHtml = `
<div class="flex justify-between items-start mb-3">
<div class="flex items-center">
<span class="handle cursor-move mr-2 text-gray-400">
<i class="fas fa-grip-vertical"></i>
</span>
<h4 class="font-medium">${question.type.charAt(0).toUpperCase() + question.type.slice(1)} Question</h4>
</div>
<div class="flex space-x-2">
<button onclick="editQuestion('${questionId}')" class="text-blue-600 hover:text-blue-800">
<i class="fas fa-edit"></i>
</button>
<button onclick="deleteQuestion('${questionId}')" class="text-red-600 hover:text-red-800">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
<div class="mb-3">
<input type="text" id="question-text-${questionId}" class="w-full px-3 py-2 border rounded-lg" value="${question.text}" placeholder="Enter question text">
</div>
<div class="mb-3">
<label class="flex items-center">
<input type="checkbox" id="question-required-${questionId}" class="mr-2" ${question.required ? 'checked' : ''}>
<span class="text-sm text-gray-700">Required</span>
</label>
</div>
`;
// Add type-specific fields
if (['radio', 'checkbox', 'select'].includes(question.type)) {
questionHtml += `
<div class="options-container mb-3" id="options-container-${questionId}">
${question.options.map(option => `
<div class="option-item mb-2 flex items-center">
<input type="text" class="option-input w-full px-3 py-1 border rounded-lg mr-2" value="${option}" placeholder="Option text">
<button class="remove-option text-red-500 hover:text-red-700">
<i class="fas fa-times"></i>
</button>
</div>
`).join('')}
</div>
<button onclick="addOption('${questionId}')" class="text-sm text-green-600 hover:text-green-800 mb-3">
<i class="fas fa-plus mr-1"></i>Add Option
</button>
`;
}
if (question.type === 'file') {
questionHtml += `
<div class="mb-3">
<select id="question-filetype-${questionId}" class="w-full px-3 py-2 border rounded-lg">
<option value="any" ${question.fileType === 'any' ? 'selected' : ''}>Any file type</option>
<option value="image" ${question.fileType === 'image' ? 'selected' : ''}>Image only</option>
<option value="pdf" ${question.fileType === 'pdf' ? 'selected' : ''}>PDF only</option>
<option value="document" ${question.fileType === 'document' ? 'selected' : ''}>Document (PDF, Word)</option>
</select>
</div>
`;
}
// Add logic if exists
if (question.logic) {
questionHtml += `
<div class="mb-3">
<label class="block text-sm font-medium text-gray-700 mb-1">Logic Jump</label>
<select id="question-logic-${questionId}" class="w-full px-3 py-2 border rounded-lg">
<option value="">No logic (continue to next question)</option>
<option value="end" ${question.logic === 'end' ? 'selected' : ''}>End survey after this question</option>
</select>
</div>
`;
}
questionHtml += `
<input type="hidden" id="question-type-${questionId}" value="${question.type}">
`;
questionElement.innerHTML = questionHtml;
questionsContainer.appendChild(questionElement);
// Make draggable
makeQuestionDraggable(`question-${questionId}`);
// Add event listeners to remove buttons
const optionsContainer = document.getElementById(`options-container-${questionId}`);
if (optionsContainer) {
const removeButtons = optionsContainer.querySelectorAll('.remove-option');
removeButtons.forEach(button => {
button.addEventListener('click', function() {
this.parentNode.parentNode.removeChild(this.parentNode);
});
});
}
});
showPage('surveyBuilder');
}
function viewResponses(surveyId) {
currentSurveyId = surveyId;
loadSurveyResponses(surveyId);
showPage('responses');
}
function loadSurveyResponses(surveyId) {
const surveys = JSON.parse(localStorage.getItem('codkSurveys'));
const survey = surveys.find(s => s.id === surveyId);
if (!survey) {
alert('Survey not found');
return;
}
// Set survey title
document.getElementById('responsesSurveyTitle').textContent = `Responses: ${survey.title}`;
// Load responses
const allResponses = JSON.parse(localStorage.getItem('codkResponses'));
const responses = allResponses.filter(r => r.surveyId === surveyId);
// Update response count in title
document.getElementById('responsesSurveyTitle').textContent += ` (${responses.length} responses)`;
// Update response table
const tableBody = document.getElementById('responsesTableBody');
tableBody.innerHTML = '';
responses.forEach(response => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${response.id.substring(0, 6)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${formatDate(response.submittedAt)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${response.county}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button onclick="viewResponseDetails('${response.id}')" class="text-green-600 hover:text-green-800">
<i class="fas fa-eye mr-1"></i>View
</button>
</td>
`;
tableBody.appendChild(row);
});
// Update charts
updateResponseRateChart(responses);
updateCountyChart(responses);
updateQuestionCharts(survey, responses);
}
function viewResponseDetails(responseId) {
const responses = JSON.parse(localStorage.getItem('codkResponses'));
const response = responses.find(r => r.id === responseId);
if (!response) {
alert('Response not found');
return;
}
const surveys = JSON.parse(localStorage.getItem('codkSurveys'));
const survey = surveys.find(s => s.id === response.surveyId);
if (!survey) {
alert('Survey not found');
return;
}
const detailsContainer = document.getElementById('responseDetails');
detailsContainer.innerHTML = `
<div class="mb-6">
<h4 class="text-lg font-semibold text-green-800 mb-2">Response Information</h4>
<div class="grid grid-cols-2 gap-4">
<div>
<p class="text-sm text-gray-500">Response ID</p>
<p class="font-medium">${response.id}</p>
</div>
<div>
<p class="text-sm text-gray-500">Submitted</p>
<p class="font-medium">${formatDateTime(response.submittedAt)}</p>
</div>
<div>
<p class="text-sm text-gray-500">County</p>
<p class="font-medium">${response.county}</p>
</div>
<div>
<p class="text-sm text-gray-500">Survey</p>
<p class="font-medium">${survey.title}</p>
</div>
</div>
</div>
<h4 class="text-lg font-semibold text-green-800 mb-4">Answers</h4>
<div class="space-y-6">
${response.answers.map(answer => `
<div class="border-b pb-4">
<p class="font-medium mb-1">${answer.questionText}</p>
<div class="text-gray-700">
${formatAnswerValue(answer)}
</div>
</div>
`).join('')}
</div>
`;
showModal('viewResponseModal');
}
function formatAnswerValue(answer) {
if (answer.type === 'checkbox
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=BizzareEmpire/cod-k" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>CoD-K National Opinion Hub</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<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.25/jspdf.plugin.autotable.min.js"></script>
<style>
/* Mobile-specific styles */
@media (max-width: 640px) {
.map-container {
height: 300px;
}
.question-card {
padding: 0.75rem;
}
.page {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.survey-card {
margin-bottom: 0.75rem;
}
}
.question-card {
transition: all 0.3s ease;
}
.question-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.dragging {
opacity: 0.5;
background-color: #f0fdf4;
}
.map-container {
height: 400px;
background-color: #f0f0f0;
position: relative;
overflow: hidden;
}
.county-dot {
position: absolute;
width: 12px;
height: 12px;
background-color: #10b981;
border-radius: 50%;
transform: translate(-50%, -50%);
transition: all 0.3s ease;
}
.county-dot:hover {
width: 16px;
height: 16px;
background-color: #059669;
}
.county-tooltip {
position: absolute;
background-color: white;
padding: 5px 10px;
border-radius: 4px;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
font-size: 12px;
pointer-events: none;
z-index: 100;
}
.fade-in {
animation: fadeIn 0.5s;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
</style>
</head>
<body class="bg-gray-50">
<!-- Navigation -->
<nav class="bg-green-800 text-white shadow-lg">
<div class="container mx-auto px-4 py-3 flex justify-between items-center">
<div class="flex items-center space-x-2">
<div class="w-10 h-10 bg-white rounded-full flex items-center justify-center">
<span class="text-green-800 font-bold text-xl">CoD-K</span>
</div>
<h1 class="text-xl font-bold">National Opinion Hub</h1>
</div>
<div class="hidden md:flex space-x-6">
<a href="#" onclick="showPage('home')" class="hover:text-green-200">Home</a>
<a href="#" onclick="showPage('surveys')" class="hover:text-green-200">Surveys</a>
<a href="#" onclick="showPage('dashboard')" class="hover:text-green-200">Dashboard</a>
<a href="#" onclick="showPage('admin')" id="adminLink" class="hover:text-green-200 hidden">Admin</a>
</div>
<div class="md:hidden flex items-center">
<button id="mobileMenuButton" class="text-white focus:outline-none">
<i class="fas fa-bars text-2xl"></i>
</button>
</div>