Closed tingaloo closed 9 years ago
Just glancing at this, but why are we geocoding upon map button click? Doesn't it make more sense to integrate it into the edit/add new location functionality?
Oh man you're absolutely right. I went tunnel vision on this fix, and went straight for ajax instead of doing it the Rails way. I'll give this a go later.
Great! Looking forward to this functionality.
My head hurts because #UPDATE immediately PATCHES the changes, so at any given time, @housing_form.location_changed? will return false. And I cannot do a check on whether location has changed specifically.
Someone with a solid understanding of ajax/callbacks can get this working I believe. I can explain this in more detail to whoever wants a greater explanation.
You can test all this yourself by literally clicking on UPDATE HOUSING FORM on each pdf and watch the latitude and longitude forms fill. Also got some awesome debugging gems to play with.
Doesn't the map popup button only show if there is a lat/lon? If so, displayHousingLocationMap and the null check could be removed.
You're right. Removed those checks, ready for pulling.
PLEASE READ: Precaching technically works, a few concerns.
This wasn't as easy as I thought. I'm pushing this out because maybe someone knows how to work with AJAX better than me. Also not following the rails way of ajax, building upon existing code.
First Concern
If longitude and latitude aren't defined, housing form's coordinates immediately update on modal display. However there is a nasty redirect ON UPDATE from the server side controller that I do not know how to get around. And even that was confusing to read.
Please see housing_forms_controller changes.
And on the server side, it looks something like this.
It will continuously patch/redirect until it reaches this error.
But it successfully updates the coordinates. Therefore the next call will retrieve the coordinates from the database, SKIPPING THE UPDATE ENTIRELY
SECOND CONCERN
Since the update happens asynchronously, the updated location and the success notification DO NOT DISPLAY UNTIL PAGE REFRESH. I think the fix would be an ajax refresh of the list. And whatever changes necessary for redirection.
BUT WE HAVE PRECACHING SO I'LL STOP HERE.