Refactor photo management and upload functionality to use HTMX for asynchronous requests

- Updated photo upload handling in `photo_manager.html` and `photo_upload.html` to utilize HTMX for file uploads, improving user experience and reducing reliance on Promises.
- Refactored caption update and primary photo toggle methods to leverage HTMX for state updates without full page reloads.
- Enhanced error handling and success notifications using HTMX events.
- Replaced fetch API calls with HTMX forms in various templates, including `homepage.html`, `park_form.html`, and `roadtrip_planner.html`, to streamline AJAX interactions.
- Improved search suggestion functionality in `search_script.html` by implementing HTMX for fetching suggestions, enhancing performance and user experience.
- Updated designer, manufacturer, and ride model forms to handle responses with HTMX, ensuring better integration and user feedback.
This commit is contained in:
pacnpal
2025-09-26 10:18:56 -04:00
parent 8aa56c463a
commit 12deafaa09
18 changed files with 1103 additions and 577 deletions

View File

@@ -360,16 +360,30 @@ function searchGlobal() {
this.isSearching = true;
// Use HTMX to fetch search results
htmx.ajax('GET', `/api/v1/search/global/?q=${encodeURIComponent(this.searchQuery)}`, {
target: '#search-results-container',
swap: 'innerHTML'
}).then(() => {
this.isSearching = false;
this.showResults = true;
}).catch(() => {
// Create temporary form for HTMX request
const tempForm = document.createElement('form');
tempForm.setAttribute('hx-get', `/api/v1/search/global/?q=${encodeURIComponent(this.searchQuery)}`);
tempForm.setAttribute('hx-target', '#search-results-container');
tempForm.setAttribute('hx-swap', 'innerHTML');
tempForm.setAttribute('hx-trigger', 'submit');
// Add HTMX event listeners
tempForm.addEventListener('htmx:afterRequest', (event) => {
this.isSearching = false;
if (event.detail.successful) {
this.showResults = true;
}
document.body.removeChild(tempForm);
});
tempForm.addEventListener('htmx:responseError', (event) => {
this.isSearching = false;
document.body.removeChild(tempForm);
});
// Execute HTMX request
document.body.appendChild(tempForm);
htmx.trigger(tempForm, 'submit');
}
</script>
{% endblock %}
@@ -412,4 +426,4 @@ document.addEventListener('DOMContentLoaded', function() {
});
});
</script>
{% endblock %}
{% endblock %}