Commit 98c68e5f71cc420ea2cad4225f045e748c8a388c
Committed by
Daniela Feitosa
1 parent
e62c8255
Exists in
master
and in
29 other branches
Improve usability on profile edit location
Showing
1 changed file
with
50 additions
and
64 deletions
Show diff stats
app/views/maps/_google_map.js.erb
@@ -9,9 +9,9 @@ var previousCenter; | @@ -9,9 +9,9 @@ var previousCenter; | ||
9 | function getAddress(latlng) { | 9 | function getAddress(latlng) { |
10 | $('location-fields').addClassName("loading"); | 10 | $('location-fields').addClassName("loading"); |
11 | 11 | ||
12 | - if (latlng != null) { | 12 | + if (latlng != null) { |
13 | geocoder.geocode( {'latLng': latlng}, showAddress); | 13 | geocoder.geocode( {'latLng': latlng}, showAddress); |
14 | - } | 14 | + } |
15 | } | 15 | } |
16 | 16 | ||
17 | function codeAddress() { | 17 | function codeAddress() { |
@@ -21,7 +21,7 @@ function codeAddress() { | @@ -21,7 +21,7 @@ function codeAddress() { | ||
21 | var address = $('profile_data_address').value + "-" + $('profile_data_zip_code').value + "," + $('profile_data_city').value+ "-" + $('profile_data_state').value + "," + country_option; | 21 | var address = $('profile_data_address').value + "-" + $('profile_data_zip_code').value + "," + $('profile_data_city').value+ "-" + $('profile_data_state').value + "," + country_option; |
22 | 22 | ||
23 | if (geocoder) { | 23 | if (geocoder) { |
24 | - geocoder.geocode( { 'address': address}, function(results, status) { | 24 | + geocoder.geocode({ 'address': address}, function(results, status) { |
25 | if (status == google.maps.GeocoderStatus.OK) { | 25 | if (status == google.maps.GeocoderStatus.OK) { |
26 | map.setCenter(results[0].geometry.location); | 26 | map.setCenter(results[0].geometry.location); |
27 | marker.setPosition(results[0].geometry.location); | 27 | marker.setPosition(results[0].geometry.location); |
@@ -78,66 +78,65 @@ function getAddressData() { | @@ -78,66 +78,65 @@ function getAddressData() { | ||
78 | } | 78 | } |
79 | 79 | ||
80 | function showAddress(results, status) { | 80 | function showAddress(results, status) { |
81 | - | ||
82 | if (status == google.maps.GeocoderStatus.OK) { | 81 | if (status == google.maps.GeocoderStatus.OK) { |
83 | - map.setCenter(results[0].geometry.location); | ||
84 | updateFields(results[0]); | 82 | updateFields(results[0]); |
85 | - | 83 | + map.setCenter(marker.getPosition()); |
86 | } else { | 84 | } else { |
87 | alert("<%=_("Address not found, reason:")%>" + translate_status(status)); | 85 | alert("<%=_("Address not found, reason:")%>" + translate_status(status)); |
88 | } | 86 | } |
89 | - | ||
90 | } | 87 | } |
91 | 88 | ||
92 | function updateFields(place) { | 89 | function updateFields(place) { |
90 | + $('location-fields').removeClassName("loading"); | ||
91 | + | ||
93 | var position = marker.getPosition(); | 92 | var position = marker.getPosition(); |
94 | $('profile_data_lat').value = position.lat(); | 93 | $('profile_data_lat').value = position.lat(); |
95 | $('profile_data_lng').value = position.lng(); | 94 | $('profile_data_lng').value = position.lng(); |
96 | - $('location-fields').removeClassName("loading"); | ||
97 | 95 | ||
98 | form = jQuery('#location-form')[0]; | 96 | form = jQuery('#location-form')[0]; |
99 | form.lat = marker.getPosition().lat(); | 97 | form.lat = marker.getPosition().lat(); |
100 | form.lng = marker.getPosition().lng(); | 98 | form.lng = marker.getPosition().lng(); |
101 | 99 | ||
102 | var components_len = place.address_components.size(); | 100 | var components_len = place.address_components.size(); |
101 | + if (components_len < 2) | ||
102 | + return; | ||
103 | 103 | ||
104 | - if(components_len < 2) | ||
105 | - { | ||
106 | - return false; | ||
107 | - } | ||
108 | - | ||
109 | - var components = place.address_components; | ||
110 | var address = ""; | 104 | var address = ""; |
111 | var zip_code = ""; | 105 | var zip_code = ""; |
112 | var city = ""; | 106 | var city = ""; |
113 | var state = ""; | 107 | var state = ""; |
114 | var country_code = ""; | 108 | var country_code = ""; |
115 | - var i = 0; | ||
116 | - | ||
117 | - for( i =0 ; i < components_len; i ++) | ||
118 | - { | ||
119 | - | ||
120 | - if (components[i].types[0] == 'country') | ||
121 | - country_code = components[i].short_name; | ||
122 | - else if (components[i].types[0] == 'administrative_area_level_1') | ||
123 | - state = components[i].long_name; | ||
124 | - else if (components[i].types[0] == 'locality') | ||
125 | - city = components[i].long_name; | ||
126 | - else if (components[i].types[0] == 'sublocality') | ||
127 | - address = components[i].long_name + "-" + address; | ||
128 | - else if (components[i].types[0] == "route") | ||
129 | - address = components[i].long_name + address; | ||
130 | - else if (components[i].types[0] == "street_number") | ||
131 | - address = address + "," + components[i].short_name ; | ||
132 | - else if (components[i].types[0] == 'postal_code') | ||
133 | - zip_code = components[i].short_name; | 109 | + |
110 | + var i; | ||
111 | + for(i=0; i < components_len; i++) { | ||
112 | + type = place.address_components[i].types[0]; | ||
113 | + value = place.address_components[i]; | ||
114 | + if (type == 'country') | ||
115 | + country_code = value.short_name; | ||
116 | + else if (type == 'administrative_area_level_1') | ||
117 | + state = value.long_name; | ||
118 | + else if (type == 'locality') | ||
119 | + city = value.long_name; | ||
120 | + else if (type == 'sublocality') | ||
121 | + address = value.long_name + "-" + address; | ||
122 | + else if (type == "route") | ||
123 | + address = value.long_name + address; | ||
124 | + else if (type == "street_number") | ||
125 | + address = address + "," + value.short_name; | ||
126 | + else if (type == 'postal_code') | ||
127 | + zip_code = value.short_name; | ||
134 | } | 128 | } |
135 | 129 | ||
136 | - $('profile_data_country').value = country_code; | ||
137 | - $('profile_data_state').value = state; | ||
138 | - $('profile_data_address').value = address; | ||
139 | - $('profile_data_city').value = city; | ||
140 | - $('profile_data_zip_code').value = zip_code; | 130 | + if (country_code) |
131 | + $('profile_data_country').value = country_code; | ||
132 | + if (state) | ||
133 | + $('profile_data_state').value = state; | ||
134 | + if (address) | ||
135 | + $('profile_data_address').value = address; | ||
136 | + if (city) | ||
137 | + $('profile_data_city').value = city; | ||
138 | + if (zip_code) | ||
139 | + $('profile_data_zip_code').value = zip_code; | ||
141 | } | 140 | } |
142 | 141 | ||
143 | 142 | ||
@@ -157,29 +156,25 @@ function initialize_map() { | @@ -157,29 +156,25 @@ function initialize_map() { | ||
157 | var myOptions = { | 156 | var myOptions = { |
158 | zoom: 8, | 157 | zoom: 8, |
159 | center: latlng, | 158 | center: latlng, |
160 | - mapTypeId: google.maps.MapTypeId.ROADMAP | 159 | + mapTypeId: google.maps.MapTypeId.HYBRID |
161 | } | 160 | } |
162 | 161 | ||
163 | center = latlng; | 162 | center = latlng; |
164 | 163 | ||
165 | map = new google.maps.Map(document.getElementById("location-map"), myOptions); | 164 | map = new google.maps.Map(document.getElementById("location-map"), myOptions); |
166 | 165 | ||
167 | - continueLoadMapV3() | ||
168 | -} | ||
169 | - | ||
170 | -function continueLoadMapV3() { | ||
171 | - | ||
172 | - marker = new google.maps.Marker({ | ||
173 | - position: center, | ||
174 | - map: map, | ||
175 | - draggable: true | ||
176 | - }); | 166 | + marker = new google.maps.Marker({ |
167 | + position: center, | ||
168 | + map: map, | ||
169 | + draggable: true | ||
170 | + }); | ||
177 | 171 | ||
178 | - google.maps.event.addListener(marker, "dragend", function() { | ||
179 | - move = false; | ||
180 | - getAddress(marker.getPosition()); | ||
181 | - enable_save(); | ||
182 | - }); | 172 | + google.maps.event.addListener(marker, "dragend", function() { |
173 | + move = false; | ||
174 | + getAddress(marker.getPosition()); | ||
175 | + map.setCenter(marker.getPosition()); | ||
176 | + enable_save(); | ||
177 | + }); | ||
183 | 178 | ||
184 | } | 179 | } |
185 | 180 | ||
@@ -188,7 +183,7 @@ window.onload = initialize_map; | @@ -188,7 +183,7 @@ window.onload = initialize_map; | ||
188 | var delay_autocomplete = 500; | 183 | var delay_autocomplete = 500; |
189 | 184 | ||
190 | jQuery.noConflict(); | 185 | jQuery.noConflict(); |
191 | -jQuery(document).ready(function (){ | 186 | +jQuery(document).ready(function () { |
192 | 187 | ||
193 | jQuery.widget( "custom.catcomplete",jQuery.ui.autocomplete, { | 188 | jQuery.widget( "custom.catcomplete",jQuery.ui.autocomplete, { |
194 | _renderMenu: function( ul, items ) { | 189 | _renderMenu: function( ul, items ) { |
@@ -204,7 +199,6 @@ jQuery(document).ready(function (){ | @@ -204,7 +199,6 @@ jQuery(document).ready(function (){ | ||
204 | } | 199 | } |
205 | }); | 200 | }); |
206 | 201 | ||
207 | - | ||
208 | jQuery("#profile_data_city").catcomplete({ | 202 | jQuery("#profile_data_city").catcomplete({ |
209 | source: "../maps/search_city", | 203 | source: "../maps/search_city", |
210 | minLength: 3, | 204 | minLength: 3, |
@@ -219,21 +213,13 @@ jQuery(document).ready(function (){ | @@ -219,21 +213,13 @@ jQuery(document).ready(function (){ | ||
219 | }); | 213 | }); |
220 | 214 | ||
221 | jQuery("#profile_data_city").keyup(function(){ | 215 | jQuery("#profile_data_city").keyup(function(){ |
222 | - | ||
223 | disable_save(); | 216 | disable_save(); |
224 | - | ||
225 | }); | 217 | }); |
226 | - | ||
227 | jQuery("#profile_data_state").keyup(function(){ | 218 | jQuery("#profile_data_state").keyup(function(){ |
228 | - | ||
229 | disable_save(); | 219 | disable_save(); |
230 | - | ||
231 | }); | 220 | }); |
232 | - | ||
233 | jQuery("#profile_data_country").change(function(){ | 221 | jQuery("#profile_data_country").change(function(){ |
234 | - | ||
235 | disable_save(); | 222 | disable_save(); |
236 | - | ||
237 | }); | 223 | }); |
238 | 224 | ||
239 | }); | 225 | }); |