bashcma / index.html
iiahmedmisau's picture
Add 3 files
2c6cd24 verified
Raw History Blame Contribute Delete
46.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FieldData Collector</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">
<style>
.form-builder {
min-height: 300px;
border: 2px dashed #cbd5e0;
transition: all 0.3s ease;
}
.form-builder:hover {
border-color: #4f46e5;
}
.question-item {
transition: all 0.2s ease;
}
.question-item:hover {
transform: translateY(-2px);
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.dragging {
opacity: 0.5;
background-color: #e0e7ff;
}
.map-container {
height: 300px;
background-color: #e5e7eb;
display: flex;
align-items: center;
justify-content: center;
color: #6b7280;
}
.sidebar {
transition: all 0.3s ease;
}
@media (max-width: 768px) {
.sidebar {
transform: translateX(-100%);
position: absolute;
z-index: 10;
height: 100vh;
}
.sidebar.open {
transform: translateX(0);
}
}
</style>
</head>
<body class="bg-gray-50">
<div class="flex h-screen overflow-hidden">
<!-- Mobile menu button -->
<button id="menuToggle" class="md:hidden fixed top-4 left-4 z-20 bg-indigo-600 text-white p-2 rounded-lg">
<i class="fas fa-bars"></i>
</button>
<!-- Sidebar -->
<div id="sidebar" class="sidebar bg-white w-64 border-r border-gray-200 flex flex-col">
<div class="p-4 border-b border-gray-200">
<h1 class="text-xl font-bold text-indigo-600 flex items-center">
<i class="fas fa-map-marked-alt mr-2"></i>
FieldData
</h1>
</div>
<nav class="flex-1 overflow-y-auto p-4">
<div class="space-y-2">
<button id="showForms" class="w-full flex items-center space-x-2 p-2 rounded-lg bg-indigo-50 text-indigo-700">
<i class="fas fa-list"></i>
<span>My Forms</span>
</button>
<button id="showBuilder" class="w-full flex items-center space-x-2 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-plus-circle"></i>
<span>Create Form</span>
</button>
<button id="showSubmissions" class="w-full flex items-center space-x-2 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-database"></i>
<span>Submissions</span>
</button>
<button id="showSettings" class="w-full flex items-center space-x-2 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-cog"></i>
<span>Settings</span>
</button>
</div>
<div class="mt-8">
<h3 class="text-xs font-semibold text-gray-500 uppercase tracking-wider">Recent Forms</h3>
<div class="mt-2 space-y-1">
<a href="#" class="block p-2 text-sm rounded hover:bg-gray-100">Household Survey</a>
<a href="#" class="block p-2 text-sm rounded hover:bg-gray-100">Health Facility</a>
<a href="#" class="block p-2 text-sm rounded hover:bg-gray-100">Agriculture Census</a>
</div>
</div>
</nav>
<div class="p-4 border-t border-gray-200">
<div class="flex items-center space-x-2">
<div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600">
<i class="fas fa-user"></i>
</div>
<div>
<p class="text-sm font-medium">Field Worker</p>
<p class="text-xs text-gray-500">Logged In</p>
</div>
</div>
</div>
</div>
<!-- Main content -->
<div class="flex-1 overflow-auto">
<!-- Header -->
<header class="bg-white border-b border-gray-200 p-4">
<div class="flex justify-between items-center">
<h2 id="pageTitle" class="text-lg font-semibold">My Forms</h2>
<div class="flex space-x-2">
<button class="bg-indigo-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2">
<i class="fas fa-sync-alt"></i>
<span>Sync</span>
</button>
<button class="bg-white border border-gray-300 px-4 py-2 rounded-lg flex items-center space-x-2">
<i class="fas fa-download"></i>
<span>Export</span>
</button>
</div>
</div>
</header>
<!-- Forms List (Default View) -->
<div id="formsView" class="p-6">
<div class="mb-6 flex justify-between items-center">
<h3 class="text-xl font-semibold">Available Forms</h3>
<button id="createNewForm" class="bg-indigo-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2">
<i class="fas fa-plus"></i>
<span>New Form</span>
</button>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<!-- Form Card 1 -->
<div class="bg-white rounded-lg border border-gray-200 overflow-hidden shadow-sm hover:shadow-md transition-shadow">
<div class="p-4 border-b border-gray-200 bg-indigo-50">
<h4 class="font-medium text-indigo-700">Household Survey</h4>
<p class="text-sm text-gray-500">Basic demographic information</p>
</div>
<div class="p-4">
<div class="flex justify-between text-sm text-gray-600 mb-3">
<span><i class="fas fa-question-circle mr-1"></i> 15 questions</span>
<span><i class="fas fa-check-circle mr-1"></i> 24 submissions</span>
</div>
<div class="flex space-x-2">
<button class="flex-1 bg-indigo-600 text-white py-1 px-3 rounded text-sm">
<i class="fas fa-play mr-1"></i> Start
</button>
<button class="flex-1 bg-white border border-gray-300 py-1 px-3 rounded text-sm">
<i class="fas fa-edit mr-1"></i> Edit
</button>
</div>
</div>
</div>
<!-- Form Card 2 -->
<div class="bg-white rounded-lg border border-gray-200 overflow-hidden shadow-sm hover:shadow-md transition-shadow">
<div class="p-4 border-b border-gray-200 bg-green-50">
<h4 class="font-medium text-green-700">Health Facility Assessment</h4>
<p class="text-sm text-gray-500">Medical resources and services</p>
</div>
<div class="p-4">
<div class="flex justify-between text-sm text-gray-600 mb-3">
<span><i class="fas fa-question-circle mr-1"></i> 32 questions</span>
<span><i class="fas fa-check-circle mr-1"></i> 8 submissions</span>
</div>
<div class="flex space-x-2">
<button class="flex-1 bg-indigo-600 text-white py-1 px-3 rounded text-sm">
<i class="fas fa-play mr-1"></i> Start
</button>
<button class="flex-1 bg-white border border-gray-300 py-1 px-3 rounded text-sm">
<i class="fas fa-edit mr-1"></i> Edit
</button>
</div>
</div>
</div>
<!-- Form Card 3 -->
<div class="bg-white rounded-lg border border-gray-200 overflow-hidden shadow-sm hover:shadow-md transition-shadow">
<div class="p-4 border-b border-gray-200 bg-yellow-50">
<h4 class="font-medium text-yellow-700">Agriculture Census</h4>
<p class="text-sm text-gray-500">Crop types and production data</p>
</div>
<div class="p-4">
<div class="flex justify-between text-sm text-gray-600 mb-3">
<span><i class="fas fa-question-circle mr-1"></i> 22 questions</span>
<span><i class="fas fa-check-circle mr-1"></i> 17 submissions</span>
</div>
<div class="flex space-x-2">
<button class="flex-1 bg-indigo-600 text-white py-1 px-3 rounded text-sm">
<i class="fas fa-play mr-1"></i> Start
</button>
<button class="flex-1 bg-white border border-gray-300 py-1 px-3 rounded text-sm">
<i class="fas fa-edit mr-1"></i> Edit
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Form Builder View (Hidden by default) -->
<div id="builderView" class="p-6 hidden">
<div class="mb-6 flex justify-between items-center">
<h3 class="text-xl font-semibold">Form Builder</h3>
<div class="flex space-x-2">
<button class="bg-white border border-gray-300 px-4 py-2 rounded-lg flex items-center space-x-2">
<i class="fas fa-save"></i>
<span>Save</span>
</button>
<button class="bg-indigo-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2">
<i class="fas fa-eye"></i>
<span>Preview</span>
</button>
</div>
</div>
<div class="flex flex-col md:flex-row gap-6">
<!-- Question Types Panel -->
<div class="w-full md:w-64 bg-white p-4 rounded-lg border border-gray-200">
<h4 class="font-medium text-gray-700 mb-3">Question Types</h4>
<div class="space-y-2">
<div draggable="true" data-type="text" class="p-2 border border-gray-200 rounded cursor-move hover:bg-gray-50 flex items-center">
<i class="fas fa-font mr-2 text-gray-500"></i>
<span>Text Input</span>
</div>
<div draggable="true" data-type="number" class="p-2 border border-gray-200 rounded cursor-move hover:bg-gray-50 flex items-center">
<i class="fas fa-hashtag mr-2 text-gray-500"></i>
<span>Number</span>
</div>
<div draggable="true" data-type="select" class="p-2 border border-gray-200 rounded cursor-move hover:bg-gray-50 flex items-center">
<i class="fas fa-list-ul mr-2 text-gray-500"></i>
<span>Select One</span>
</div>
<div draggable="true" data-type="multiselect" class="p-2 border border-gray-200 rounded cursor-move hover:bg-gray-50 flex items-center">
<i class="fas fa-list-check mr-2 text-gray-500"></i>
<span>Select Multiple</span>
</div>
<div draggable="true" data-type="date" class="p-2 border border-gray-200 rounded cursor-move hover:bg-gray-50 flex items-center">
<i class="fas fa-calendar-day mr-2 text-gray-500"></i>
<span>Date</span>
</div>
<div draggable="true" data-type="location" class="p-2 border border-gray-200 rounded cursor-move hover:bg-gray-50 flex items-center">
<i class="fas fa-map-marker-alt mr-2 text-gray-500"></i>
<span>Location</span>
</div>
<div draggable="true" data-type="photo" class="p-2 border border-gray-200 rounded cursor-move hover:bg-gray-50 flex items-center">
<i class="fas fa-camera mr-2 text-gray-500"></i>
<span>Photo</span>
</div>
</div>
</div>
<!-- Form Builder Area -->
<div class="flex-1">
<div class="bg-white p-4 rounded-lg border border-gray-200 mb-4">
<input type="text" placeholder="Form Title" class="w-full p-2 border-b border-gray-300 text-xl font-medium focus:outline-none focus:border-indigo-500">
<input type="text" placeholder="Form Description" class="w-full p-2 text-gray-600 focus:outline-none">
</div>
<div id="formBuilder" class="form-builder bg-white p-4 rounded-lg border border-gray-200 min-h-64">
<p class="text-gray-500 text-center py-10">Drag and drop question types here to build your form</p>
<!-- Sample questions (would be added dynamically) -->
<div class="question-item bg-gray-50 p-4 rounded-lg border border-gray-200 mb-3">
<div class="flex justify-between items-start mb-2">
<input type="text" placeholder="Question text" class="flex-1 p-2 border-b border-gray-300 font-medium focus:outline-none focus:border-indigo-500" value="What is your name?">
<select class="ml-2 p-1 border border-gray-300 rounded text-sm">
<option>Required</option>
<option>Optional</option>
</select>
</div>
<input type="text" class="w-full p-2 bg-white border border-gray-300 rounded" placeholder="Text answer">
<div class="mt-2 flex justify-end space-x-2">
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-trash"></i>
</button>
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Submissions View (Hidden by default) -->
<div id="submissionsView" class="p-6 hidden">
<div class="mb-6 flex justify-between items-center">
<h3 class="text-xl font-semibold">Form Submissions</h3>
<div class="flex space-x-2">
<select class="border border-gray-300 rounded-lg px-3 py-2">
<option>All Forms</option>
<option>Household Survey</option>
<option>Health Facility</option>
<option>Agriculture Census</option>
</select>
<button class="bg-indigo-600 text-white px-4 py-2 rounded-lg flex items-center space-x-2">
<i class="fas fa-download"></i>
<span>Export</span>
</button>
</div>
</div>
<div class="bg-white rounded-lg border border-gray-200 overflow-hidden">
<div class="grid grid-cols-12 bg-gray-50 p-3 border-b border-gray-200 font-medium text-gray-700">
<div class="col-span-2">Form</div>
<div class="col-span-2">Date</div>
<div class="col-span-5">Location</div>
<div class="col-span-2">Status</div>
<div class="col-span-1">Actions</div>
</div>
<!-- Submission row -->
<div class="grid grid-cols-12 p-3 border-b border-gray-200 hover:bg-gray-50 items-center">
<div class="col-span-2 font-medium">Household Survey</div>
<div class="col-span-2 text-sm text-gray-600">May 15, 2023</div>
<div class="col-span-5 text-sm text-gray-600 flex items-center">
<i class="fas fa-map-marker-alt mr-1 text-red-500"></i>
<span>6.5244° N, 3.3792° E</span>
</div>
<div class="col-span-2">
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full">Complete</span>
</div>
<div class="col-span-1 flex justify-end">
<button class="text-indigo-600 hover:text-indigo-800 p-1">
<i class="fas fa-eye"></i>
</button>
</div>
</div>
<!-- Submission row -->
<div class="grid grid-cols-12 p-3 border-b border-gray-200 hover:bg-gray-50 items-center">
<div class="col-span-2 font-medium">Health Facility</div>
<div class="col-span-2 text-sm text-gray-600">May 14, 2023</div>
<div class="col-span-5 text-sm text-gray-600 flex items-center">
<i class="fas fa-map-marker-alt mr-1 text-red-500"></i>
<span>6.6018° N, 3.3515° E</span>
</div>
<div class="col-span-2">
<span class="bg-yellow-100 text-yellow-800 text-xs px-2 py-1 rounded-full">Partial</span>
</div>
<div class="col-span-1 flex justify-end">
<button class="text-indigo-600 hover:text-indigo-800 p-1">
<i class="fas fa-eye"></i>
</button>
</div>
</div>
<!-- Submission row -->
<div class="grid grid-cols-12 p-3 border-b border-gray-200 hover:bg-gray-50 items-center">
<div class="col-span-2 font-medium">Agriculture Census</div>
<div class="col-span-2 text-sm text-gray-600">May 12, 2023</div>
<div class="col-span-5 text-sm text-gray-600 flex items-center">
<i class="fas fa-map-marker-alt mr-1 text-red-500"></i>
<span>6.4531° N, 3.3958° E</span>
</div>
<div class="col-span-2">
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full">Complete</span>
</div>
<div class="col-span-1 flex justify-end">
<button class="text-indigo-600 hover:text-indigo-800 p-1">
<i class="fas fa-eye"></i>
</button>
</div>
</div>
</div>
</div>
<!-- Settings View (Hidden by default) -->
<div id="settingsView" class="p-6 hidden">
<div class="mb-6">
<h3 class="text-xl font-semibold">Settings</h3>
<p class="text-gray-600">Configure your application preferences</p>
</div>
<div class="bg-white rounded-lg border border-gray-200 p-6">
<div class="space-y-6">
<div>
<h4 class="font-medium mb-3">User Profile</h4>
<div class="flex items-center space-x-4 mb-4">
<div class="w-16 h-16 rounded-full bg-indigo-100 flex items-center justify-center">
<i class="fas fa-user text-2xl text-indigo-600"></i>
</div>
<div>
<button class="text-indigo-600 text-sm font-medium">Change Photo</button>
<p class="text-xs text-gray-500">JPG or PNG, max 2MB</p>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">First Name</label>
<input type="text" class="w-full border border-gray-300 rounded-lg px-3 py-2" value="Field">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Last Name</label>
<input type="text" class="w-full border border-gray-300 rounded-lg px-3 py-2" value="Worker">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" class="w-full border border-gray-300 rounded-lg px-3 py-2" value="worker@example.com">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Phone</label>
<input type="tel" class="w-full border border-gray-300 rounded-lg px-3 py-2" value="+1234567890">
</div>
</div>
</div>
<div class="border-t border-gray-200 pt-6">
<h4 class="font-medium mb-3">Application Settings</h4>
<div class="space-y-4">
<div class="flex items-center justify-between">
<div>
<p class="font-medium">Offline Mode</p>
<p class="text-sm text-gray-500">Collect data without internet connection</p>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" class="sr-only peer" checked>
<div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
<div class="flex items-center justify-between">
<div>
<p class="font-medium">Auto-sync</p>
<p class="text-sm text-gray-500">Automatically sync when online</p>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" class="sr-only peer" checked>
<div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
<div class="flex items-center justify-between">
<div>
<p class="font-medium">Location Tracking</p>
<p class="text-sm text-gray-500">Record GPS coordinates for submissions</p>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" class="sr-only peer" checked>
<div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
</div>
</div>
<div class="border-t border-gray-200 pt-6">
<h4 class="font-medium mb-3">Data Management</h4>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<button class="border border-gray-300 rounded-lg p-3 hover:bg-gray-50">
<div class="flex items-center space-x-2">
<div class="p-2 rounded-full bg-indigo-100 text-indigo-600">
<i class="fas fa-database"></i>
</div>
<div>
<p class="font-medium">Backup Data</p>
<p class="text-xs text-gray-500">Create local backup</p>
</div>
</div>
</button>
<button class="border border-gray-300 rounded-lg p-3 hover:bg-gray-50">
<div class="flex items-center space-x-2">
<div class="p-2 rounded-full bg-green-100 text-green-600">
<i class="fas fa-cloud-upload-alt"></i>
</div>
<div>
<p class="font-medium">Sync Now</p>
<p class="text-xs text-gray-500">Upload all data</p>
</div>
</div>
</button>
<button class="border border-gray-300 rounded-lg p-3 hover:bg-gray-50">
<div class="flex items-center space-x-2">
<div class="p-2 rounded-full bg-red-100 text-red-600">
<i class="fas fa-trash-alt"></i>
</div>
<div>
<p class="font-medium">Clear Cache</p>
<p class="text-xs text-gray-500">Free up space</p>
</div>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Toggle mobile menu
document.getElementById('menuToggle').addEventListener('click', function() {
document.getElementById('sidebar').classList.toggle('open');
});
// View switching
const views = {
forms: document.getElementById('formsView'),
builder: document.getElementById('builderView'),
submissions: document.getElementById('submissionsView'),
settings: document.getElementById('settingsView')
};
const buttons = {
showForms: document.getElementById('showForms'),
showBuilder: document.getElementById('showBuilder'),
showSubmissions: document.getElementById('showSubmissions'),
showSettings: document.getElementById('showSettings'),
createNewForm: document.getElementById('createNewForm')
};
const pageTitle = document.getElementById('pageTitle');
function switchView(activeView) {
// Hide all views
Object.values(views).forEach(view => view.classList.add('hidden'));
// Show active view
views[activeView].classList.remove('hidden');
// Update page title
const titles = {
forms: 'My Forms',
builder: 'Form Builder',
submissions: 'Submissions',
settings: 'Settings'
};
pageTitle.textContent = titles[activeView];
// Update active button in sidebar
document.querySelectorAll('nav button').forEach(btn => {
btn.classList.remove('bg-indigo-50', 'text-indigo-700');
btn.classList.add('hover:bg-gray-100');
});
const activeButton = {
forms: buttons.showForms,
builder: buttons.showBuilder,
submissions: buttons.showSubmissions,
settings: buttons.showSettings
}[activeView];
activeButton.classList.add('bg-indigo-50', 'text-indigo-700');
activeButton.classList.remove('hover:bg-gray-100');
// Close mobile menu if open
document.getElementById('sidebar').classList.remove('open');
}
// Add event listeners
buttons.showForms.addEventListener('click', () => switchView('forms'));
buttons.showBuilder.addEventListener('click', () => switchView('builder'));
buttons.showSubmissions.addEventListener('click', () => switchView('submissions'));
buttons.showSettings.addEventListener('click', () => switchView('settings'));
buttons.createNewForm.addEventListener('click', () => switchView('builder'));
// Initialize with forms view
switchView('forms');
// Drag and drop functionality for form builder
const formBuilder = document.getElementById('formBuilder');
const questionTypes = document.querySelectorAll('[draggable="true"]');
questionTypes.forEach(question => {
question.addEventListener('dragstart', function(e) {
e.dataTransfer.setData('text/plain', this.dataset.type);
this.classList.add('opacity-50');
});
question.addEventListener('dragend', function() {
this.classList.remove('opacity-50');
});
});
formBuilder.addEventListener('dragover', function(e) {
e.preventDefault();
this.classList.add('border-indigo-500', 'bg-indigo-50');
});
formBuilder.addEventListener('dragleave', function() {
this.classList.remove('border-indigo-500', 'bg-indigo-50');
});
formBuilder.addEventListener('drop', function(e) {
e.preventDefault();
this.classList.remove('border-indigo-500', 'bg-indigo-50');
const questionType = e.dataTransfer.getData('text/plain');
addQuestionToBuilder(questionType);
});
function addQuestionToBuilder(type) {
const questionId = 'q' + Date.now();
let questionHtml = '';
switch(type) {
case 'text':
questionHtml = `
<div class="question-item bg-gray-50 p-4 rounded-lg border border-gray-200 mb-3" draggable="true" data-id="${questionId}">
<div class="flex justify-between items-start mb-2">
<input type="text" placeholder="Question text" class="flex-1 p-2 border-b border-gray-300 font-medium focus:outline-none focus:border-indigo-500">
<select class="ml-2 p-1 border border-gray-300 rounded text-sm">
<option>Required</option>
<option>Optional</option>
</select>
</div>
<input type="text" class="w-full p-2 bg-white border border-gray-300 rounded" placeholder="Text answer">
<div class="mt-2 flex justify-end space-x-2">
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-trash"></i>
</button>
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
`;
break;
case 'number':
questionHtml = `
<div class="question-item bg-gray-50 p-4 rounded-lg border border-gray-200 mb-3" draggable="true" data-id="${questionId}">
<div class="flex justify-between items-start mb-2">
<input type="text" placeholder="Question text" class="flex-1 p-2 border-b border-gray-300 font-medium focus:outline-none focus:border-indigo-500">
<select class="ml-2 p-1 border border-gray-300 rounded text-sm">
<option>Required</option>
<option>Optional</option>
</select>
</div>
<input type="number" class="w-full p-2 bg-white border border-gray-300 rounded" placeholder="Number answer">
<div class="mt-2 flex justify-end space-x-2">
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-trash"></i>
</button>
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
`;
break;
case 'select':
questionHtml = `
<div class="question-item bg-gray-50 p-4 rounded-lg border border-gray-200 mb-3" draggable="true" data-id="${questionId}">
<div class="flex justify-between items-start mb-2">
<input type="text" placeholder="Question text" class="flex-1 p-2 border-b border-gray-300 font-medium focus:outline-none focus:border-indigo-500">
<select class="ml-2 p-1 border border-gray-300 rounded text-sm">
<option>Required</option>
<option>Optional</option>
</select>
</div>
<div class="space-y-2 mb-2">
<div class="flex items-center">
<input type="radio" name="${questionId}" class="mr-2" disabled>
<input type="text" class="flex-1 p-1 border-b border-gray-300 focus:outline-none focus:border-indigo-500" placeholder="Option 1">
<button class="ml-2 text-gray-400 hover:text-red-500">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<button class="text-sm text-indigo-600 flex items-center">
<i class="fas fa-plus-circle mr-1"></i>
Add option
</button>
<div class="mt-2 flex justify-end space-x-2">
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-trash"></i>
</button>
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
`;
break;
case 'location':
questionHtml = `
<div class="question-item bg-gray-50 p-4 rounded-lg border border-gray-200 mb-3" draggable="true" data-id="${questionId}">
<div class="flex justify-between items-start mb-2">
<input type="text" placeholder="Question text" class="flex-1 p-2 border-b border-gray-300 font-medium focus:outline-none focus:border-indigo-500" value="Location">
<select class="ml-2 p-1 border border-gray-300 rounded text-sm">
<option>Required</option>
<option>Optional</option>
</select>
</div>
<div class="map-container rounded-lg mb-2">
<div class="text-center">
<i class="fas fa-map-marker-alt text-3xl text-red-500 mb-2"></i>
<p>GPS coordinates will be recorded</p>
</div>
</div>
<div class="mt-2 flex justify-end space-x-2">
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-trash"></i>
</button>
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
`;
break;
case 'photo':
questionHtml = `
<div class="question-item bg-gray-50 p-4 rounded-lg border border-gray-200 mb-3" draggable="true" data-id="${questionId}">
<div class="flex justify-between items-start mb-2">
<input type="text" placeholder="Question text" class="flex-1 p-2 border-b border-gray-300 font-medium focus:outline-none focus:border-indigo-500" value="Take a photo">
<select class="ml-2 p-1 border border-gray-300 rounded text-sm">
<option>Required</option>
<option>Optional</option>
</select>
</div>
<div class="border-2 border-dashed border-gray-300 rounded-lg p-6 text-center">
<i class="fas fa-camera text-3xl text-gray-400 mb-2"></i>
<p class="text-gray-500">Photo will be captured here</p>
</div>
<div class="mt-2 flex justify-end space-x-2">
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-trash"></i>
</button>
<button class="text-gray-500 hover:text-gray-700">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
`;
break;
}
formBuilder.insertAdjacentHTML('beforeend', questionHtml);
// Remove the "drag questions here" message if it exists
const placeholder = formBuilder.querySelector('p.text-center');
if (placeholder) {
placeholder.remove();
}
}
// Make questions in builder draggable
formBuilder.addEventListener('dragstart', function(e) {
if (e.target.classList.contains('question-item')) {
e.dataTransfer.setData('text/plain', e.target.dataset.id);
e.target.classList.add('dragging');
}
});
formBuilder.addEventListener('dragend', function(e) {
if (e.target.classList.contains('question-item')) {
e.target.classList.remove('dragging');
}
});
formBuilder.addEventListener('dragover', function(e) {
e.preventDefault();
const draggingQuestion = document.querySelector('.dragging');
if (draggingQuestion) {
const afterElement = getDragAfterElement(formBuilder, e.clientY);
if (afterElement) {
formBuilder.insertBefore(draggingQuestion, afterElement);
} else {
formBuilder.appendChild(draggingQuestion);
}
}
});
function getDragAfterElement(container, y) {
const draggableElements = [...container.querySelectorAll('.question-item:not(.dragging)')];
return draggableElements.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
if (offset < 0 && offset > closest.offset) {
return { offset: offset, element: child };
} else {
return closest;
}
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
</script>
<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=iiahmedmisau/bashcma" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>