]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/changeset.js
Merge remote-tracking branch 'upstream/pull/5667'
[rails.git] / app / assets / javascripts / index / changeset.js
index 1ec5940b2d694a6c9f9a7f576540f810041790a2..6feefbc2dc0217d7645de3f0b8464a8b1d355a19 100644 (file)
@@ -12,7 +12,7 @@ OSM.Changeset = function (map) {
     const changesetData = content.find("[data-changeset]").data("changeset");
     changesetData.type = "changeset";
 
-    const hashParams = OSM.parseHash(window.location.hash);
+    const hashParams = OSM.parseHash(location.hash);
     initialize();
     map.addObject(changesetData, function (bounds) {
       if (!hashParams.center && bounds.isValid()) {
@@ -24,33 +24,36 @@ OSM.Changeset = function (map) {
   };
 
   function updateChangeset(method, url, include_data) {
-    let data;
+    const data = new URLSearchParams();
 
     content.find("#comment-error").prop("hidden", true);
     content.find("button[data-method][data-url]").prop("disabled", true);
 
     if (include_data) {
-      data = { text: content.find("textarea").val() };
-    } else {
-      data = {};
+      data.set("text", content.find("textarea").val());
     }
 
-    $.ajax({
-      url: url,
-      type: method,
-      oauth: true,
-      data: data,
-      success: function () {
-        OSM.loadSidebarContent(window.location.pathname, page.load);
-      },
-      error: function (xhr) {
+    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(location.pathname, page.load);
+      })
+      .catch(error => {
         content.find("button[data-method][data-url]").prop("disabled", false);
         content.find("#comment-error")
-          .text(xhr.responseText)
+          .text(error.message)
           .prop("hidden", false)
           .get(0).scrollIntoView({ block: "nearest" });
-      }
-    });
+      });
   }
 
   function initialize() {