X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3d3b2b47964ec91ef1ab1946b7258a06665caced..b4a9d7537785f1b44ea4db42bed69127fbe323ae:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 4903703cd..96870f600 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -78,6 +78,9 @@ $(document).ready(function () { }); }; + const token = $("head").data("oauthToken"); + if (token) OSM.oauth = { authorization: "Bearer " + token }; + const params = OSM.mapParams(); map.attributionControl.setPrefix(""); @@ -233,20 +236,20 @@ $(document).ready(function () { }); if (object && object.type !== "note") query.set("select", object.type + object.id); // can't select notes - sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query, function () { - if (object && object.type === "note") { - const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) }); - sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery); - } - }); + sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query) + .then(() => { + if (object && object.type === "note") { + const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) }); + sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery); + } + }) + .catch(() => { + // eslint-disable-next-line no-alert + alert(I18n.t("site.index.remote_failed")); + }); - function sendRemoteEditCommand(url, callback) { - fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) }) - .then(callback) - .catch(function () { - // eslint-disable-next-line no-alert - alert(I18n.t("site.index.remote_failed")); - }); + function sendRemoteEditCommand(url) { + return fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) }); } return false;