449 lines
28 KiB
Plaintext
449 lines
28 KiB
Plaintext
<div class="container mx-auto py-10 px-4 sm:px-6 lg:px-8">
|
|
<h1 class="text-3xl font-bold text-green-300 mb-8 text-center">Post a New Listing</h1>
|
|
|
|
<div id="post-form-steps" class="max-w-3xl mx-auto bg-white p-6 sm:p-8 rounded-lg shadow-xl">
|
|
<!-- Step Indicators -->
|
|
<div class="flex justify-between mb-8 sm:mb-10">
|
|
<div id="step-indicator-1" class="step-indicator active-step text-center flex-1">
|
|
<div class="w-8 h-8 sm:w-10 sm:h-10 mx-auto rounded-full bg-green-300 text-white flex items-center justify-center text-sm sm:text-base">1</div>
|
|
<p class="text-xs sm:text-sm mt-1 sm:mt-2">Description</p>
|
|
</div>
|
|
<div id="step-indicator-2" class="step-indicator text-center text-gray-500 flex-1">
|
|
<div class="w-8 h-8 sm:w-10 sm:h-10 mx-auto rounded-full bg-gray-300 flex items-center justify-center text-sm sm:text-base">2</div>
|
|
<p class="text-xs sm:text-sm mt-1 sm:mt-2">Location</p>
|
|
</div>
|
|
<div id="step-indicator-3" class="step-indicator text-center text-gray-500 flex-1">
|
|
<div class="w-8 h-8 sm:w-10 sm:h-10 mx-auto rounded-full bg-gray-300 flex items-center justify-center text-sm sm:text-base">3</div>
|
|
<p class="text-xs sm:text-sm mt-1 sm:mt-2">Price & Availability</p>
|
|
</div>
|
|
<div id="step-indicator-4" class="step-indicator text-center text-gray-500 flex-1">
|
|
<div class="w-8 h-8 sm:w-10 sm:h-10 mx-auto rounded-full bg-gray-300 flex items-center justify-center text-sm sm:text-base">4</div>
|
|
<p class="text-xs sm:text-sm mt-1 sm:mt-2">Contact</p>
|
|
</div>
|
|
</div>
|
|
|
|
<form id="new-listing-form">
|
|
<!-- Step 1: Description -->
|
|
<div id="step-1" class="form-step active-step">
|
|
<h2 class="text-xl sm:text-2xl font-semibold text-green-300 mb-6">Step 1: Listing Description</h2>
|
|
<div class="space-y-5">
|
|
<div>
|
|
<label for="photo" class="block text-sm font-medium text-gray-700 mb-1">Listing Photo</label>
|
|
<input type="file" id="photo" name="photo" class="w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-indigo-50 file:text-green-300 hover:file:bg-indigo-100 border border-gray-400 rounded-sm cursor-pointer focus:outline-none focus:border-green-300" accept="image/*">
|
|
<p class="text-sm text-gray-500 mt-1">Upload one image for your listing (e.g., JPG, PNG).</p>
|
|
</div>
|
|
<div>
|
|
<label for="title" class="block text-sm font-medium text-gray-700 mb-1">Title</label>
|
|
<input type="text" id="title" name="title" placeholder="e.g., Modern Coworking Hub with Great Coffee" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="description" class="block text-sm font-medium text-gray-700 mb-1">Description</label>
|
|
<textarea id="description" name="description" rows="4" placeholder="Describe your space, amenities, and what makes it unique..." class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm"></textarea>
|
|
</div>
|
|
<div>
|
|
<label for="space-type" class="block text-sm font-medium text-gray-700 mb-1">Space Type</label>
|
|
<select id="space-type" name="space-type" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm bg-white">
|
|
<option value="">Select a space type</option>
|
|
<option value="coworking">Coworking</option>
|
|
<option value="room">Private Room</option>
|
|
<option value="conference">Conference Room</option>
|
|
<option value="event-space">Event Space</option>
|
|
<option value="virtual-office">Virtual Office</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="mt-8 flex justify-end">
|
|
<button type="button" class="next-step-btn bg-green-300 hover:bg-indigo-800 text-white font-semibold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 transition-colors">
|
|
Next <span aria-hidden="true">→</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Step 2: Location -->
|
|
<div id="step-2" class="form-step hidden">
|
|
<h2 class="text-xl sm:text-2xl font-semibold text-green-300 mb-6">Step 2: Location</h2>
|
|
<div class="space-y-5">
|
|
<div class="relative">
|
|
<label for="location-search" class="block text-sm font-medium text-gray-700 mb-1">Select Location</label>
|
|
<input type="text" id="location-search" name="location-search" placeholder="Type to search for a city or area..." class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm" autocomplete="off">
|
|
<div id="location-dropdown" class="absolute z-20 mt-1 w-full rounded-md bg-white shadow-lg hidden ring-1 ring-black ring-opacity-5 max-h-60 overflow-y-auto py-1">
|
|
<!-- Example items, real implementation would populate this dynamically or use a service -->
|
|
<a href="#" data-value="Manila, Philippines" class="block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-50 hover:text-green-300 location-item">Manila, Philippines</a>
|
|
<a href="#" data-value="Makati, Philippines" class="block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-50 hover:text-green-300 location-item">Makati, Philippines</a>
|
|
<a href="#" data-value="Quezon City, Philippines" class="block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-50 hover:text-green-300 location-item">Quezon City, Philippines</a>
|
|
<a href="#" data-value="Cebu City, Philippines" class="block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-50 hover:text-green-300 location-item">Cebu City, Philippines</a>
|
|
<a href="#" data-value="Taguig, Philippines" class="block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-50 hover:text-green-300 location-item">Taguig, Philippines</a>
|
|
<p class="px-4 py-2 text-sm text-gray-500 no-results hidden">No locations found.</p>
|
|
</div>
|
|
<input type="hidden" id="selected-location" name="selected-location">
|
|
</div>
|
|
<div>
|
|
<label for="address-line-1" class="block text-sm font-medium text-gray-700 mb-1">Address Line 1</label>
|
|
<input type="text" id="address-line-1" name="address-line-1" placeholder="e.g., 123 Main St, Incub8 Building" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="address-line-2" class="block text-sm font-medium text-gray-700 mb-1">Address Line 2 (Optional)</label>
|
|
<input type="text" id="address-line-2" name="address-line-2" placeholder="e.g., Centennial Road, Brgy. Batong Dalig" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
</div>
|
|
<div class="mt-8 flex justify-between">
|
|
<button type="button" class="prev-step-btn bg-gray-200 hover:bg-gray-300 text-gray-700 font-semibold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-opacity-50 transition-colors">
|
|
<span aria-hidden="true">←</span> Previous
|
|
</button>
|
|
<button type="button" class="next-step-btn bg-green-300 hover:bg-indigo-800 text-white font-semibold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 transition-colors">
|
|
Next <span aria-hidden="true">→</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Step 3: Price & Availability -->
|
|
<div id="step-3" class="form-step hidden">
|
|
<h2 class="text-xl sm:text-2xl font-semibold text-green-300 mb-6">Step 3: Price & Availability</h2>
|
|
<div class="space-y-6">
|
|
<div>
|
|
<label for="price" class="block text-sm font-medium text-gray-700 mb-1">Price (PHP per day)</label>
|
|
<div class="relative mt-1 rounded-md shadow-sm">
|
|
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
|
|
<span class="text-gray-500 sm:text-sm">₱</span>
|
|
</div>
|
|
<input type="number" id="price" name="price" placeholder="e.g., 1200" class="w-full pl-7 pr-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm" min="0">
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<h3 class="text-md font-medium text-gray-800 mb-2">Availability Date Range</h3>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div>
|
|
<label for="availability-start-date" class="block text-xs font-medium text-gray-700 mb-1">Start Date</label>
|
|
<input type="date" id="availability-start-date" name="availability-start-date" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="availability-end-date" class="block text-xs font-medium text-gray-700 mb-1">End Date</label>
|
|
<input type="date" id="availability-end-date" name="availability-end-date" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<h3 class="text-md font-medium text-gray-800 mb-3">Weekly Availability & Hours</h3>
|
|
{% assign days_list = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" | split: "," %}
|
|
|
|
<!-- Day Selector Tab Buttons -->
|
|
<div class="mb-4">
|
|
<div class="flex flex-wrap border-b border-gray-300">
|
|
{% for day_label in days_list %}
|
|
<button type="button"
|
|
class="day-tab-button -mb-px py-2 px-4 border-b-2 border-transparent text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none"
|
|
data-day-target="{{ day_label | downcase }}">
|
|
{{ day_label }}
|
|
</button>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Content for each day's availability -->
|
|
{% for day_label in days_list %}
|
|
<div id="availability-content-{{ day_label | downcase }}" class="day-availability-content hidden">
|
|
<div class="bg-gray-50 p-4 rounded-lg shadow-sm space-y-4">
|
|
<label for="available-{{ day_label | downcase }}" class="flex items-center justify-between w-full cursor-pointer">
|
|
<span class="text-sm font-medium text-gray-900">Available on {{ day_label }}</span>
|
|
<input type="checkbox"
|
|
id="available-{{ day_label | downcase }}"
|
|
name="available_days[]"
|
|
value="{{ day_label }}"
|
|
class="sr-only peer day-specific-availability-toggle"
|
|
data-day="{{ day_label | downcase }}"
|
|
onchange="toggleDayTimeSelection('{{ day_label | downcase }}')">
|
|
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-offset-2 peer-focus:ring-indigo-500 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 id="time-selection-{{ day_label | downcase }}" class="day-specific-time-inputs mt-4 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3 hidden">
|
|
<div>
|
|
<label for="start-time-{{ day_label | downcase }}" class="block text-xs font-medium text-gray-700 mb-1">Open</label>
|
|
<input type="time" id="start-time-{{ day_label | downcase }}" name="start_time_{{ day_label | downcase }}" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-white">
|
|
</div>
|
|
<div>
|
|
<label for="end-time-{{ day_label | downcase }}" class="block text-xs font-medium text-gray-700 mb-1">Close</label>
|
|
<input type="time" id="end-time-{{ day_label | downcase }}" name="end_time_{{ day_label | downcase }}" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-white">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
<div class="mt-8 flex justify-between">
|
|
<button type="button" class="prev-step-btn bg-gray-200 hover:bg-gray-300 text-gray-700 font-semibold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-opacity-50 transition-colors">
|
|
<span aria-hidden="true">←</span> Previous
|
|
</button>
|
|
<button type="button" class="next-step-btn bg-green-300 hover:bg-indigo-800 text-white font-semibold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 transition-colors">
|
|
Next <span aria-hidden="true">→</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Step 4: Contact Information -->
|
|
<div id="step-4" class="form-step hidden">
|
|
<h2 class="text-xl sm:text-2xl font-semibold text-green-300 mb-6">Step 4: Contact Information</h2>
|
|
<div class="space-y-5">
|
|
<div>
|
|
<label for="space-name" class="block text-sm font-medium text-gray-700 mb-1">Coworking Space Name</label>
|
|
<input type="text" id="space-name" name="space_name" placeholder="e.g., The Productive Corner" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div>
|
|
<label for="contact-first-name" class="block text-sm font-medium text-gray-700 mb-1">Contact Person - First Name</label>
|
|
<input type="text" id="contact-first-name" name="contact_first_name" placeholder="John" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="contact-last-name" class="block text-sm font-medium text-gray-700 mb-1">Contact Person - Last Name</label>
|
|
<input type="text" id="contact-last-name" name="contact_last_name" placeholder="Doe" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label for="contact-number" class="block text-sm font-medium text-gray-700 mb-1">Contact Number</label>
|
|
<input type="tel" id="contact-number" name="contact_number" placeholder="e.g., 09171234567 or +639171234567" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="contact-email" class="block text-sm font-medium text-gray-700 mb-1">Email Address</label>
|
|
<input type="email" id="contact-email" name="contact_email" placeholder="you@example.com" class="w-full px-3 py-2 border border-gray-400 rounded-sm focus:outline-none focus:border-green-300 sm:text-sm">
|
|
</div>
|
|
</div>
|
|
<div class="mt-8 flex justify-between items-center">
|
|
<button type="button" class="prev-step-btn bg-gray-200 hover:bg-gray-300 text-gray-700 font-semibold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-opacity-50 transition-colors">
|
|
<span aria-hidden="true">←</span> Previous
|
|
</button>
|
|
<button type="submit" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-50 transition-colors text-lg">
|
|
Submit Listing
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.form-step {
|
|
/* hidden by default, JS will manage visibility */
|
|
}
|
|
.active-step {
|
|
display: block !important;
|
|
}
|
|
.step-indicator.active-step p {
|
|
color: #4338ca; /* indigo-700 */
|
|
font-weight: 600; /* semibold */
|
|
}
|
|
.step-indicator .bg-green-300 {
|
|
/* Active indicator circle */
|
|
}
|
|
.step-indicator .bg-gray-300 {
|
|
/* Inactive indicator circle */
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const steps = document.querySelectorAll('.form-step');
|
|
const stepIndicators = document.querySelectorAll('.step-indicator');
|
|
let currentStep = 0;
|
|
|
|
function showStep(stepIndex) {
|
|
steps.forEach((step, index) => {
|
|
step.classList.toggle('active-step', index === stepIndex);
|
|
step.classList.toggle('hidden', index !== stepIndex);
|
|
});
|
|
updateStepIndicators(stepIndex);
|
|
window.scrollTo(0, 0); // Scroll to top when step changes
|
|
}
|
|
|
|
function updateStepIndicators(activeIndex) {
|
|
stepIndicators.forEach((indicator, index) => {
|
|
const circle = indicator.querySelector('div:first-child'); // The numbered circle
|
|
const text = indicator.querySelector('p'); // The text label
|
|
|
|
if (index === activeIndex) {
|
|
circle.classList.remove('bg-gray-300');
|
|
circle.classList.add('bg-green-300', 'text-white');
|
|
text.classList.remove('text-gray-500');
|
|
text.classList.add('text-green-300', 'font-semibold');
|
|
} else if (index < activeIndex) { // Completed steps
|
|
circle.classList.remove('bg-gray-300');
|
|
circle.classList.add('bg-green-300', 'text-white'); // Mark as completed
|
|
text.classList.remove('text-gray-500', 'text-green-300', 'font-semibold');
|
|
text.classList.add('text-gray-700'); // Neutral color for completed text
|
|
} else { // Future steps
|
|
circle.classList.remove('bg-green-300', 'text-white');
|
|
circle.classList.add('bg-gray-300');
|
|
text.classList.remove('text-green-300', 'font-semibold');
|
|
text.classList.add('text-gray-500');
|
|
}
|
|
});
|
|
}
|
|
|
|
document.querySelectorAll('.next-step-btn').forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
// Add validation logic here if needed before proceeding
|
|
if (currentStep < steps.length - 1) {
|
|
currentStep++;
|
|
showStep(currentStep);
|
|
}
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('.prev-step-btn').forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
if (currentStep > 0) {
|
|
currentStep--;
|
|
showStep(currentStep);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Location Search Dropdown Logic
|
|
const locationInput = document.getElementById('location-search');
|
|
const locationDropdown = document.getElementById('location-dropdown');
|
|
const selectedLocationInput = document.getElementById('selected-location');
|
|
const noResultsP = locationDropdown.querySelector('.no-results');
|
|
const allLocationItems = Array.from(locationDropdown.querySelectorAll('a.location-item'));
|
|
|
|
if (locationInput) {
|
|
locationInput.addEventListener('keyup', function() {
|
|
const filter = locationInput.value.toLowerCase();
|
|
let hasVisibleItems = false;
|
|
allLocationItems.forEach(item => {
|
|
const text = item.textContent.toLowerCase();
|
|
if (text.includes(filter)) {
|
|
item.style.display = '';
|
|
hasVisibleItems = true;
|
|
} else {
|
|
item.style.display = 'none';
|
|
}
|
|
});
|
|
noResultsP.classList.toggle('hidden', hasVisibleItems);
|
|
locationDropdown.classList.toggle('hidden', !filter && !locationInput.matches(':focus'));
|
|
if (filter && locationInput.matches(':focus')) {
|
|
locationDropdown.classList.remove('hidden');
|
|
}
|
|
});
|
|
|
|
allLocationItems.forEach(item => {
|
|
item.addEventListener('click', function(event) {
|
|
event.preventDefault();
|
|
locationInput.value = this.dataset.value; // Use data-value for cleaner text
|
|
selectedLocationInput.value = this.dataset.value;
|
|
locationDropdown.classList.add('hidden');
|
|
});
|
|
});
|
|
|
|
locationInput.addEventListener('focus', () => {
|
|
if(locationInput.value || allLocationItems.some(item => item.style.display !== 'none')) {
|
|
locationDropdown.classList.remove('hidden');
|
|
}
|
|
});
|
|
|
|
document.addEventListener('click', function(event) {
|
|
if (!locationInput.contains(event.target) && !locationDropdown.contains(event.target)) {
|
|
locationDropdown.classList.add('hidden');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Availability: Toggle time selection based on day checkbox
|
|
window.toggleDayTimeSelection = function(day) {
|
|
const checkbox = document.getElementById(`available-${day}`); // This ID is from the checkbox itself
|
|
const timeSelectionDiv = document.getElementById(`time-selection-${day}`); // This ID is for the time inputs container
|
|
|
|
if (checkbox && timeSelectionDiv) {
|
|
if (checkbox.checked) {
|
|
timeSelectionDiv.classList.remove('hidden');
|
|
} else {
|
|
timeSelectionDiv.classList.add('hidden');
|
|
// Optionally clear time inputs
|
|
const startTimeInput = document.getElementById(`start-time-${day}`);
|
|
const endTimeInput = document.getElementById(`end-time-${day}`);
|
|
if(startTimeInput) startTimeInput.value = '';
|
|
if(endTimeInput) endTimeInput.value = '';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Weekly Availability Tabs Logic
|
|
const dayTabButtons = document.querySelectorAll('.day-tab-button');
|
|
const dayAvailabilityContents = document.querySelectorAll('.day-availability-content');
|
|
|
|
function setActiveDayTab(targetDay) {
|
|
dayTabButtons.forEach(button => {
|
|
const isTarget = button.dataset.dayTarget === targetDay;
|
|
button.classList.toggle('border-indigo-500', isTarget); // Active tab style
|
|
button.classList.toggle('text-indigo-600', isTarget);
|
|
button.classList.toggle('font-semibold', isTarget); // Make active tab font bolder
|
|
button.classList.toggle('text-gray-500', !isTarget); // Inactive tab style
|
|
button.classList.toggle('hover:border-gray-300', !isTarget); // Corrected hover for inactive
|
|
button.classList.toggle('border-transparent', !isTarget);
|
|
});
|
|
|
|
dayAvailabilityContents.forEach(content => {
|
|
content.classList.toggle('hidden', content.id !== `availability-content-${targetDay}`);
|
|
});
|
|
|
|
// Ensure the time selection visibility is correct for the newly shown tab
|
|
const activeCheckbox = document.querySelector(`#availability-content-${targetDay} .day-specific-availability-toggle`);
|
|
if (activeCheckbox) {
|
|
// Call toggleDayTimeSelection to correctly show/hide based on checkbox state
|
|
toggleDayTimeSelection(targetDay);
|
|
}
|
|
}
|
|
|
|
dayTabButtons.forEach(button => {
|
|
button.addEventListener('click', function () {
|
|
setActiveDayTab(this.dataset.dayTarget);
|
|
});
|
|
});
|
|
|
|
// Initialize with the first day active (e.g., Monday) or based on existing data if applicable
|
|
if (dayTabButtons.length > 0) {
|
|
// Check if any day is already checked (e.g. form reload with validation errors)
|
|
let initiallySelectedDay = dayTabButtons[0].dataset.dayTarget; // Default to first tab
|
|
for (let i = 0; i < dayAvailabilityContents.length; i++) {
|
|
const content = dayAvailabilityContents[i];
|
|
const checkbox = content.querySelector('.day-specific-availability-toggle');
|
|
if (checkbox && checkbox.checked) {
|
|
initiallySelectedDay = checkbox.dataset.day;
|
|
break;
|
|
}
|
|
}
|
|
setActiveDayTab(initiallySelectedDay);
|
|
}
|
|
|
|
// Form submission
|
|
const newListingForm = document.getElementById('new-listing-form');
|
|
if (newListingForm) {
|
|
newListingForm.addEventListener('submit', function(event) {
|
|
event.preventDefault();
|
|
// Basic validation example: Check if title is filled
|
|
const titleInput = document.getElementById('title');
|
|
if (titleInput && titleInput.value.trim() === '') {
|
|
alert('Please enter a title for your listing.');
|
|
// Potentially switch to the step with the error
|
|
// showStep(0); // Assuming title is on step 0
|
|
titleInput.focus();
|
|
return;
|
|
}
|
|
|
|
// Add more validation as needed for other fields
|
|
|
|
alert('Listing Submitted! (This is a demo and data is not saved.)');
|
|
// For a real submission:
|
|
// const formData = new FormData(this);
|
|
// fetch('/your-submit-endpoint', { method: 'POST', body: formData })
|
|
// .then(response => response.json())
|
|
// .then(data => console.log(data))
|
|
// .catch(error => console.error('Error:', error));
|
|
// this.reset(); // Optionally reset the form
|
|
// showStep(0); // Go back to the first step
|
|
});
|
|
}
|
|
showStep(currentStep); // Initialize the first step visibility
|
|
});
|
|
</script>
|