From: Tom Hughes Date: Sun, 16 Feb 2025 13:18:14 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/5685' X-Git-Tag: live~185 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/c50e4f50c4fef0b11970202d3c7f95cdc5b620ba?hp=--cc Merge remote-tracking branch 'upstream/pull/5685' --- c50e4f50c4fef0b11970202d3c7f95cdc5b620ba diff --cc app/assets/javascripts/index.js index 4903703cd,0d235834d..0fa85a0cc --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@@ -78,7 -78,10 +78,10 @@@ $(document).ready(function () }); }; + const token = $("head").data("oauthToken"); + if (token) OSM.oauth = { authorization: "Bearer " + token }; + - var params = OSM.mapParams(); + const params = OSM.mapParams(); map.attributionControl.setPrefix(""); diff --cc app/assets/javascripts/index/new_note.js index 73fcda97c,6b24be07d..b1457d10b --- a/app/assets/javascripts/index/new_note.js +++ b/app/assets/javascripts/index/new_note.js @@@ -34,11 -34,10 +34,10 @@@ OSM.NewNote = function (map) }); function createNote(location, text, callback) { - $.ajax({ - url: "/api/0.6/notes.json", - type: "POST", - oauth: true, - data: { - fetch("/api/0.6/notes.json?", { ++ fetch("/api/0.6/notes.json", { + method: "POST", + headers: { ...OSM.oauth }, + body: new URLSearchParams({ lat: location.lat, lon: location.lng, text diff --cc app/assets/javascripts/index/note.js index 466a5451e,db5a62456..b9310a1af --- a/app/assets/javascripts/index/note.js +++ b/app/assets/javascripts/index/note.js @@@ -33,23 -39,37 +33,37 @@@ OSM.Note = function (map) initialize(path, id); }; - function initialize(path, id) { + function initialize(path, id, skipMoveToNote) { content.find("button[name]").on("click", function (e) { e.preventDefault(); - const data = $(e.target).data(); - const name = $(e.target).attr("name"); - const ajaxSettings = { - url: data.url, - type: data.method, - oauth: true, - success: () => { + const { url, method } = $(e.target).data(), + name = $(e.target).attr("name"), + data = new URLSearchParams(); + content.find("button[name]").prop("disabled", true); + + if (name !== "subscribe" && name !== "unsubscribe" && name !== "reopen") { + data.set("text", content.find("textarea").val()); + } + + fetch(url, { + method: method, + headers: { ...OSM.oauth }, + body: data + }) + .then(response => { + if (response.ok) return response; + return response.text().then(text => { + throw new Error(text); + }); + }) + .then(() => { OSM.loadSidebarContent(path, () => { - initialize(path, id); + initialize(path, id, false); }); - }, - error: (xhr) => { + }) + .catch(error => { content.find("#comment-error") - .text(xhr.responseText) + .text(error.message) .prop("hidden", false) .get(0).scrollIntoView({ block: "nearest" }); updateButtons();