]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/user.js
Improve error handling for routing engines
[rails.git] / app / assets / javascripts / user.js
1 //= require leaflet.locate
2
3 $(document).ready(function () {
4   if ($("#map").length) {
5     var map = L.map("map", {
6       attributionControl: false,
7       zoomControl: false
8     }).addLayer(new L.OSM.Mapnik());
9
10     var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
11
12     L.OSM.zoom({position: position})
13       .addTo(map);
14
15     L.control.locate({
16       position: position,
17       strings: {
18         title: I18n.t('javascripts.map.locate.title'),
19         popup: I18n.t('javascripts.map.locate.popup')
20       }
21     }).addTo(map);
22
23     if (OSM.home) {
24       map.setView([OSM.home.lat, OSM.home.lon], 12);
25     } else {
26       map.setView([0, 0], 0);
27     }
28
29     if ($("#map").hasClass("set_location")) {
30       var marker = L.marker([0, 0], {icon: OSM.getUserIcon()});
31
32       if (OSM.home) {
33         marker.setLatLng([OSM.home.lat, OSM.home.lon]);
34         marker.addTo(map);
35       }
36
37       map.on("click", function (e) {
38         if ($('#updatehome').is(':checked')) {
39           var zoom = map.getZoom(),
40               precision = OSM.zoomPrecision(zoom),
41               location = e.latlng.wrap();
42
43           $('#homerow').removeClass();
44           $('#home_lat').val(location.lat.toFixed(precision));
45           $('#home_lon').val(location.lng.toFixed(precision));
46
47           marker.setLatLng(e.latlng);
48           marker.addTo(map);
49         }
50       });
51     } else {
52       $("[data-user]").each(function () {
53         var user = $(this).data('user');
54         if (user.lon && user.lat) {
55           L.marker([user.lat, user.lon], {icon: OSM.getUserIcon(user.icon)}).addTo(map)
56             .bindPopup(user.description);
57         }
58       });
59     }
60   }
61
62   function updateAuthUID() {
63     var provider = $("select#user_auth_provider").val();
64
65     if (provider === "openid") {
66       $("input#user_auth_uid").show().prop("disabled", false);
67     } else {
68       $("input#user_auth_uid").hide().prop("disabled", true);
69     }
70   }
71
72   updateAuthUID();
73
74   $("select#user_auth_provider").on("change", updateAuthUID);
75
76   function enableAuth() {
77     $("#auth_prompt").hide();
78     $("#auth_field").show();
79     $("#user_auth_uid").prop("disabled", false);
80   }
81
82   function disableAuth() {
83     $("#auth_prompt").show();
84     $("#auth_field").hide();
85     $("#user_auth_uid").prop("disabled", true);
86   }
87
88   $("#auth_enable").click(enableAuth);
89
90   if ($("select#user_auth_provider").val() === "") {
91     disableAuth();
92   } else {
93     enableAuth();
94   }
95 });