]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/user.js
Merge remote-tracking branch 'upstream/pull/2431'
[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     var locate = L.control.locate({
16       position: position,
17       icon: "icon geolocate",
18       iconLoading: "icon geolocate",
19       strings: {
20         title: I18n.t("javascripts.map.locate.title"),
21         popup: function (options) {
22           return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
23         }
24       }
25     }).addTo(map);
26
27     var locateContainer = locate.getContainer();
28
29     $(locateContainer)
30       .removeClass("leaflet-control-locate leaflet-bar")
31       .addClass("control-locate")
32       .children("a")
33       .attr("href", "#")
34       .removeClass("leaflet-bar-part leaflet-bar-part-single")
35       .addClass("control-button");
36
37     if (OSM.home) {
38       map.setView([OSM.home.lat, OSM.home.lon], 12);
39     } else {
40       map.setView([0, 0], 0);
41     }
42
43     if ($("#map").hasClass("set_location")) {
44       var marker = L.marker([0, 0], { icon: OSM.getUserIcon() });
45
46       if (OSM.home) {
47         marker.setLatLng([OSM.home.lat, OSM.home.lon]);
48         marker.addTo(map);
49       }
50
51       map.on("click", function (e) {
52         if ($("#updatehome").is(":checked")) {
53           var zoom = map.getZoom(),
54               precision = OSM.zoomPrecision(zoom),
55               location = e.latlng.wrap();
56
57           $("#homerow").removeClass();
58           $("#home_lat").val(location.lat.toFixed(precision));
59           $("#home_lon").val(location.lng.toFixed(precision));
60
61           marker.setLatLng(e.latlng);
62           marker.addTo(map);
63         }
64       });
65     } else {
66       $("[data-user]").each(function () {
67         var user = $(this).data("user");
68         if (user.lon && user.lat) {
69           L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
70             .bindPopup(user.description);
71         }
72       });
73     }
74   }
75
76   function updateAuthUID() {
77     var provider = $("select#user_auth_provider").val();
78
79     if (provider === "openid") {
80       $("input#user_auth_uid").show().prop("disabled", false);
81     } else {
82       $("input#user_auth_uid").hide().prop("disabled", true);
83     }
84   }
85
86   updateAuthUID();
87
88   $("select#user_auth_provider").on("change", updateAuthUID);
89
90   $("input#user_avatar").on("change", function () {
91     $("#avatar_action_new").prop("checked", true);
92   });
93
94   function enableAuth() {
95     $("#auth_prompt").hide();
96     $("#auth_field").show();
97     $("#user_auth_uid").prop("disabled", false);
98   }
99
100   function disableAuth() {
101     $("#auth_prompt").show();
102     $("#auth_field").hide();
103     $("#user_auth_uid").prop("disabled", true);
104   }
105
106   $("#auth_enable").click(enableAuth);
107
108   if ($("select#user_auth_provider").val() === "") {
109     disableAuth();
110   } else {
111     enableAuth();
112   }
113
114   $("#user_all").change(function () {
115     $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
116   });
117
118   $("#content.user_confirm").each(function () {
119     $(this).hide();
120     $(this).find("#confirm").submit();
121   });
122
123   $("input[name=legale]").change(function () {
124     var url = $(this).data("url");
125
126     $("#contributorTerms").html("<img src='" + OSM.SEARCHING + "' />");
127     $("#contributorTerms").load(url);
128   });
129
130   $("#read_ct").on("click", function () {
131     $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
132   });
133
134   $("#read_tou").on("click", function () {
135     $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));
136   });
137 });