mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:31:08 -05:00
- Add complete backend/ directory with full Django application - Add frontend/ directory with Vite + TypeScript setup ready for Next.js - Add comprehensive shared/ directory with: - Complete documentation and memory-bank archives - Media files and avatars (letters, park/ride images) - Deployment scripts and automation tools - Shared types and utilities - Add architecture/ directory with migration guides - Configure pnpm workspace for monorepo development - Update .gitignore to exclude .django_tailwind_cli/ build artifacts - Preserve all historical documentation in shared/docs/memory-bank/ - Set up proper structure for full-stack development with shared resources
82 lines
3.4 KiB
JavaScript
82 lines
3.4 KiB
JavaScript
function locationAutocomplete(field, filterParks = false) {
|
|
return {
|
|
query: '',
|
|
suggestions: [],
|
|
fetchSuggestions() {
|
|
let url;
|
|
const params = new URLSearchParams({
|
|
q: this.query,
|
|
filter_parks: filterParks
|
|
});
|
|
|
|
switch (field) {
|
|
case 'country':
|
|
url = '/parks/ajax/countries/';
|
|
break;
|
|
case 'region':
|
|
url = '/parks/ajax/regions/';
|
|
// Add country parameter if we're fetching regions
|
|
const countryInput = document.getElementById(filterParks ? 'country' : 'id_country_name');
|
|
if (countryInput && countryInput.value) {
|
|
params.append('country', countryInput.value);
|
|
}
|
|
break;
|
|
case 'city':
|
|
url = '/parks/ajax/cities/';
|
|
// Add country and region parameters if we're fetching cities
|
|
const regionInput = document.getElementById(filterParks ? 'region' : 'id_region_name');
|
|
const cityCountryInput = document.getElementById(filterParks ? 'country' : 'id_country_name');
|
|
if (regionInput && regionInput.value && cityCountryInput && cityCountryInput.value) {
|
|
params.append('country', cityCountryInput.value);
|
|
params.append('region', regionInput.value);
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (url) {
|
|
fetch(`${url}?${params}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
this.suggestions = data;
|
|
});
|
|
}
|
|
},
|
|
selectSuggestion(suggestion) {
|
|
this.query = suggestion.name;
|
|
this.suggestions = [];
|
|
|
|
// If this is a form field (not filter), update hidden fields
|
|
if (!filterParks) {
|
|
const hiddenField = document.getElementById(`id_${field}`);
|
|
if (hiddenField) {
|
|
hiddenField.value = suggestion.id;
|
|
}
|
|
|
|
// Clear dependent fields when parent field changes
|
|
if (field === 'country') {
|
|
const regionInput = document.getElementById('id_region_name');
|
|
const cityInput = document.getElementById('id_city_name');
|
|
const regionHidden = document.getElementById('id_region');
|
|
const cityHidden = document.getElementById('id_city');
|
|
|
|
if (regionInput) regionInput.value = '';
|
|
if (cityInput) cityInput.value = '';
|
|
if (regionHidden) regionHidden.value = '';
|
|
if (cityHidden) cityHidden.value = '';
|
|
} else if (field === 'region') {
|
|
const cityInput = document.getElementById('id_city_name');
|
|
const cityHidden = document.getElementById('id_city');
|
|
|
|
if (cityInput) cityInput.value = '';
|
|
if (cityHidden) cityHidden.value = '';
|
|
}
|
|
}
|
|
|
|
// Trigger form submission for filters
|
|
if (filterParks) {
|
|
htmx.trigger('#park-filters', 'change');
|
|
}
|
|
}
|
|
};
|
|
}
|