Merge lp:~daker/loco-team-portal/fix.738751 into lp:loco-team-portal
- fix.738751
- Merge into 0.2
Proposed by
Adnane Belmadiaf
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Adnane Belmadiaf | ||||
Approved revision: | 638 | ||||
Merged at revision: | 639 | ||||
Proposed branch: | lp:~daker/loco-team-portal/fix.738751 | ||||
Merge into: | lp:loco-team-portal | ||||
Diff against target: |
404 lines (+112/-58) 4 files modified
loco_directory/media/css/styles.css (+9/-3) loco_directory/media/js/jquery-ubuntu-maps.js (+77/-34) loco_directory/templates/venues/venue_update.html (+21/-17) loco_directory/venues/forms.py (+5/-4) |
||||
To merge this branch: | bzr merge lp:~daker/loco-team-portal/fix.738751 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
LoCo Team Portal Developers | Pending | ||
Review via email: mp+158763@code.launchpad.net |
Commit message
Autoset TZ/City/
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'loco_directory/media/css/styles.css' |
2 | --- loco_directory/media/css/styles.css 2013-03-30 22:07:37 +0000 |
3 | +++ loco_directory/media/css/styles.css 2013-04-13 17:57:24 +0000 |
4 | @@ -327,12 +327,18 @@ |
5 | |
6 | #venue-map { |
7 | height: 200px; |
8 | - margin-top: 5px; |
9 | margin-bottom: 10px; |
10 | + border: 1px solid #CCCCCC; |
11 | + -moz-border-radius: 4px; |
12 | + border-radius: 4px; |
13 | + -webkit-border-radius: 4px; |
14 | + padding: 2px; |
15 | + box-shadow: 0 1px 0px rgba(204,204,204,0.5); |
16 | + border-bottom: 1px solid #C7C9C9; |
17 | } |
18 | |
19 | -.venue-map { |
20 | - min-height: 250px; |
21 | +#venue-map div { |
22 | + margin-top: 0; |
23 | } |
24 | |
25 | .f { |
26 | |
27 | === modified file 'loco_directory/media/js/jquery-ubuntu-maps.js' |
28 | --- loco_directory/media/js/jquery-ubuntu-maps.js 2011-03-06 20:23:23 +0000 |
29 | +++ loco_directory/media/js/jquery-ubuntu-maps.js 2013-04-13 17:57:24 +0000 |
30 | @@ -8,8 +8,8 @@ |
31 | * http://jquery.org/license |
32 | */ |
33 | |
34 | -(function ($) { |
35 | - $.fn.extend({ |
36 | +(function ($) { |
37 | + $.fn.extend({ |
38 | showLocations: function (options) { |
39 | var defaults = { |
40 | markers_url: null, // http://link/to/json/markers or /link/to/json/markers |
41 | @@ -43,7 +43,7 @@ |
42 | }, |
43 | // Add the window where the details are shown when clicked on a marker |
44 | infowindow = new google.maps.InfoWindow(); |
45 | - |
46 | + |
47 | options = $.extend(defaults, options); |
48 | |
49 | // TODO: rewrite this one |
50 | @@ -65,7 +65,7 @@ |
51 | }; |
52 | infowindow.ajaxloader = null; |
53 | infowindow.showLoader = function (pos) { |
54 | - // Set a temporary loader while the data is retreved from the server |
55 | + // Set a temporary loader while the data is retreved from the server |
56 | if (this.ajaxloader === null) { |
57 | // TODO: allow user defined ajax loader |
58 | this.ajaxloader = getAjaxLoader(); |
59 | @@ -76,18 +76,18 @@ |
60 | var $data = data, |
61 | $pos = pos, |
62 | ifw = this; |
63 | - |
64 | + |
65 | if (!$.tmpl) { |
66 | alert('jQuery.tmpl is not installed\nYou can download here:\nhttp://github.com/jquery/jquery-tmpl'); |
67 | return false; |
68 | } |
69 | - |
70 | + |
71 | this.showLoader(pos); |
72 | - $.ajax({ |
73 | - url: url, |
74 | + $.ajax({ |
75 | + url: url, |
76 | dataType: 'html', |
77 | success: function (template) { |
78 | - ifw.show($(template).tmpl($data)[0], $pos); |
79 | + ifw.show($(template).tmpl($data)[0], $pos); |
80 | }, |
81 | error: function () { |
82 | ifw.show(options.ajax_load_error, $pos); |
83 | @@ -97,14 +97,14 @@ |
84 | infowindow.showHTML = function (url, pos) { |
85 | var $pos = pos, |
86 | ifw = this; |
87 | - |
88 | + |
89 | this.showLoader(pos); |
90 | //TODO: Check for better same-origin in url |
91 | if (url.slice(0, 4) == 'http'){ |
92 | ifw.show($('<iframe>').attr('src', url)[0], $pos); |
93 | } else { |
94 | - $.ajax({ |
95 | - url: url, |
96 | + $.ajax({ |
97 | + url: url, |
98 | dataType: 'html', |
99 | success: function (html) { |
100 | ifw.show(html, $pos); |
101 | @@ -122,7 +122,7 @@ |
102 | url_match = url.match(pattern), // Matches the url for ${...} and returns a list of matches |
103 | param = null, // Used for getting a specific param from the marker |
104 | tag = null; // The tags in the match pattern |
105 | - |
106 | + |
107 | for (tag in url_match) { |
108 | if (url_match.hasOwnProperty(tag)) { |
109 | param = url_match[tag]; |
110 | @@ -131,7 +131,7 @@ |
111 | } |
112 | return url; |
113 | } |
114 | - |
115 | + |
116 | // Function executed when clicked on a cluster object |
117 | function clusterClicked(cluster) { |
118 | if (options.cluster_tmpl) { |
119 | @@ -142,7 +142,7 @@ |
120 | // Function that is executed when user clicks on a marker |
121 | function markerClicked() { |
122 | var url = null; |
123 | - |
124 | + |
125 | if (options.marker_content_url) { |
126 | url = constructUrl(options.marker_content_url, this); |
127 | infowindow.showHTML(url, this.position); |
128 | @@ -160,7 +160,7 @@ |
129 | idx = null, // Index |
130 | lat = options.position_name.lat, // The parameter that contains the latitude |
131 | lng = options.position_name.lng; // The parameter that contains the longitude |
132 | - |
133 | + |
134 | if (markers[0].fields) { |
135 | // Django model |
136 | // Use django pk and fields parameters |
137 | @@ -177,7 +177,7 @@ |
138 | marker_list.push(gmarker); |
139 | } |
140 | } |
141 | - |
142 | + |
143 | } else { |
144 | // Use normal parameters |
145 | for (idx in markers) { |
146 | @@ -194,7 +194,7 @@ |
147 | } |
148 | } |
149 | mc.addMarkers(marker_list); |
150 | - |
151 | + |
152 | // If there is only one marker |
153 | if (options.single_marker_zoom && marker_list.length === 1) { |
154 | // Make sure the map is initialized |
155 | @@ -205,7 +205,7 @@ |
156 | }, 100); |
157 | } |
158 | } |
159 | - |
160 | + |
161 | return $(this).each(function (i, html_element) { |
162 | var map = new google.maps.Map(html_element, options.mapOptions), |
163 | markerCluster = new MarkerClusterer(map, [], options.mcOptions), |
164 | @@ -217,13 +217,13 @@ |
165 | // FIXME: Manually override the zoomOnClick because of this bug |
166 | // http://www.devcomments.com/V3-MarkerClusterer-zoomOnClick-issue-at255452.htm |
167 | markerCluster.zoomOnClick_ = false; |
168 | - |
169 | + |
170 | // Attach the info window to the curernt map |
171 | infowindow.map = map; |
172 | - |
173 | + |
174 | // When clicked on a cluster, call the event |
175 | google.maps.event.addListener(markerCluster, 'clusterclick', clusterClicked); |
176 | - |
177 | + |
178 | // Try W3C Geolocation (Preferred) |
179 | // Ask the user for their location and set the map to it |
180 | if (options.user_location_zoom && navigator.geolocation) { |
181 | @@ -233,7 +233,7 @@ |
182 | map.setZoom(options.user_location_zoom); |
183 | }); |
184 | } |
185 | - |
186 | + |
187 | // Load the list of markers into the map |
188 | if (options.markers_url) { |
189 | $.getJSON(options.markers_url, function (markers) { |
190 | @@ -242,7 +242,7 @@ |
191 | } else if (options.markers_list) { |
192 | createMarkers(map, markerCluster, options.markers_list); |
193 | } |
194 | - |
195 | + |
196 | if (filter) { |
197 | filterer = (function (markerCluster) { |
198 | var mc = markerCluster, |
199 | @@ -254,9 +254,9 @@ |
200 | visible_markers = [], |
201 | m = null, |
202 | a = null; |
203 | - |
204 | + |
205 | event.preventDefault(); |
206 | - |
207 | + |
208 | for (m in markers) { |
209 | if (markers.hasOwnProperty(m)) { |
210 | marker = markers[m]; |
211 | @@ -291,6 +291,9 @@ |
212 | var defaults = { |
213 | html_lng: null, |
214 | html_lat: null, |
215 | + html_tz: null, |
216 | + html_country: null, |
217 | + html_continent: null, |
218 | marker_icon: null, |
219 | markers: [], |
220 | html_addr: null, |
221 | @@ -302,19 +305,59 @@ |
222 | } |
223 | }; |
224 | options = $.extend(defaults, options); |
225 | - |
226 | + |
227 | function showPositionHTML(location) { |
228 | + var geocoder = new google.maps.Geocoder(); |
229 | + geocoder.geocode({'latLng': location}, function(results, status) { |
230 | + if (status == google.maps.GeocoderStatus.OK) { |
231 | + if (results[0]) { |
232 | + $('#id_address').val(results[0].formatted_address); |
233 | + |
234 | + $.each(results[0].address_components, function(){ |
235 | + if(this.types[0]=="locality"){ |
236 | + $('#id_city').val(this.long_name); |
237 | + } |
238 | + }); |
239 | + } |
240 | + } |
241 | + }); |
242 | + |
243 | if (options.html_lng && options.html_lat) { |
244 | if (location.lat() && location.lng()) { |
245 | options.html_lat.val(location.lat()); |
246 | options.html_lng.val(location.lng()); |
247 | + if (options.html_tz && options.html_country && options.html_continent) { |
248 | + $.getJSON("http://ws.geonames.org/timezoneJSON?lat=" + location.lat() + "&lng=" + location.lng(), |
249 | + function(json) { |
250 | + $(options.html_tz).filter(function() { |
251 | + return $(this).text() == json.timezoneId; |
252 | + }).prop('selected', true); |
253 | + |
254 | + $(options.html_country).filter(function() { |
255 | + return $(this).text() == json.countryName; |
256 | + }).prop('selected', true); |
257 | + |
258 | + $.getJSON("http://ws.geonames.org/countryInfoJSON?country=" + json.countryCode, |
259 | + function(json) { |
260 | + if (typeof json.geonames[0].continentName !== "undefined") { |
261 | + $(options.html_continent).filter(function() { |
262 | + return $(this).text() == json.geonames[0].continentName; |
263 | + }).prop('selected', true); |
264 | + } |
265 | + } |
266 | + ); |
267 | + } |
268 | + ); |
269 | + } |
270 | } |
271 | } |
272 | + |
273 | + |
274 | } |
275 | - |
276 | + |
277 | function setMarker(map, location) { |
278 | var marker = null; |
279 | - |
280 | + |
281 | if (options.markers.length) { |
282 | marker = options.markers[0]; |
283 | marker.setPosition(location); |
284 | @@ -334,11 +377,11 @@ |
285 | showPositionHTML(marker.getPosition()); |
286 | }); |
287 | } |
288 | - |
289 | + |
290 | map.setCenter(location); |
291 | showPositionHTML(marker.getPosition()); |
292 | } |
293 | - |
294 | + |
295 | return $(this).each(function (i, html_element) { |
296 | var map = new google.maps.Map($(html_element)[0], options.mapOptions), |
297 | geoCoder = new google.maps.Geocoder(), |
298 | @@ -350,7 +393,7 @@ |
299 | options.html_addr.each(function (i, item) { |
300 | address.push(item.value); |
301 | }); |
302 | - |
303 | + |
304 | geoCoder.geocode({address: address.join(' ')}, function (results, status) { |
305 | if (status === google.maps.GeocoderStatus.OK) { |
306 | setMarker(map, results[0].geometry.location); |
307 | @@ -361,13 +404,13 @@ |
308 | google.maps.event.addListener(map, 'click', function (event) { |
309 | setMarker(map, event.latLng); |
310 | }); |
311 | - |
312 | + |
313 | if (options.html_lat.val() && options.html_lng.val()) { |
314 | location = new google.maps.LatLng(options.html_lat.val(), options.html_lng.val()); |
315 | setMarker(map, location); |
316 | } |
317 | }); |
318 | - |
319 | + |
320 | } |
321 | }); |
322 | }(jQuery)); |
323 | |
324 | === modified file 'loco_directory/templates/venues/venue_update.html' |
325 | --- loco_directory/templates/venues/venue_update.html 2013-02-21 20:31:16 +0000 |
326 | +++ loco_directory/templates/venues/venue_update.html 2013-04-13 17:57:24 +0000 |
327 | @@ -7,19 +7,6 @@ |
328 | {{ form.media }} |
329 | {% endblock %} |
330 | |
331 | -{% block extrafooter %} |
332 | -<script type="text/javascript"> |
333 | -//<![CDATA[ |
334 | - $(function(){ |
335 | - $('#venue-map-selector').selectLocation({html_lng: $("#id_longitude"), |
336 | - html_lat: $("#id_latitude"), |
337 | - html_addr: $("#id_country, #id_spr, #id_city, #id_address, #id_continent"), |
338 | - marker_icon: '{{ MEDIA_URL }}img/marker.png'}); |
339 | - }); |
340 | -//]]> |
341 | -</script> |
342 | -{% endblock %} |
343 | - |
344 | {% block content %} |
345 | <div class="row"> |
346 | <section class="span-9"> |
347 | @@ -29,13 +16,30 @@ |
348 | <h2>{% if venue_object %}{% trans "Update Venue" %}{% else %}{% trans "New Venue" %}{% endif %}</h2> |
349 | {{ form.as_template }} |
350 | {% if is_popup %}<input type="hidden" name="_popup" value="1">{% endif %} |
351 | - <input type="submit" name="submit" value="Submit" class="submit-button" /> |
352 | + <input type="submit" name="submit" value="Submit" class="btn" /> |
353 | </form> |
354 | </div> |
355 | </div> |
356 | </section> |
357 | </div> |
358 | - |
359 | -<section class="minor-content alone venue-map" id="venue-map-selector" title="{% trans "Select venue position" %}"> </section> |
360 | - |
361 | +{% endblock %} |
362 | + |
363 | + |
364 | +{% block closure %} |
365 | +<script type="text/javascript"> |
366 | +//<![CDATA[ |
367 | + $(function(){ |
368 | + $('<div id="venue-map"></div>').insertAfter('#id_address'); |
369 | + $('#venue-map').selectLocation({ |
370 | + html_lng: $("#id_longitude"), |
371 | + html_lat: $("#id_latitude"), |
372 | + html_tz: $("#id_tz option"), |
373 | + html_country: $("#id_country option"), |
374 | + html_continent: $("#id_continent option"), |
375 | + html_addr: $("#id_country, #id_spr, #id_city, #id_address, #id_continent"), |
376 | + marker_icon: '{{ MEDIA_URL }}img/marker.png' |
377 | + }); |
378 | + }); |
379 | +//]]> |
380 | +</script> |
381 | {% endblock %} |
382 | |
383 | === modified file 'loco_directory/venues/forms.py' |
384 | --- loco_directory/venues/forms.py 2013-02-21 20:31:16 +0000 |
385 | +++ loco_directory/venues/forms.py 2013-04-13 17:57:24 +0000 |
386 | @@ -20,13 +20,14 @@ |
387 | """ |
388 | class Meta: |
389 | model = Venue |
390 | + fields = ('name', 'address', 'longitude', 'latitude', 'tz', 'continent', 'country', 'spr', 'city', 'venue_url', 'comment') |
391 | |
392 | class Media: |
393 | js = ( |
394 | - 'http://maps.google.com/maps/api/js?sensor=false&language=%(language)s®ion=%(region)s' % {'language': _('en'), 'region': _('US')}, |
395 | - 'http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_packed.js', |
396 | - settings.MEDIA_URL + 'js/jquery-ubuntu-maps.js' |
397 | - ) |
398 | + 'http://maps.google.com/maps/api/js?sensor=false&language=%(language)s®ion=%(region)s' % {'language': _('en'), 'region': _('US')}, |
399 | + 'http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_packed.js', |
400 | + settings.MEDIA_URL + 'js/jquery-ubuntu-maps.js' |
401 | + ) |
402 | |
403 | def clean(self): |
404 | self.cleaned_data['name'] = validate_name(self.cleaned_data.get('name')) |