]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/note.js
Set zoom in id iframe data
[rails.git] / app / assets / javascripts / index / note.js
index 466a5451e8c8da83e54f81b5410242c9278b6e1b..b9310a1af9e159d159dcef7254988d8623dc3983 100644 (file)
@@ -36,32 +36,38 @@ OSM.Note = function (map) {
   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, false);
           });
-        },
-        error: (xhr) => {
+        })
+        .catch(error => {
           content.find("#comment-error")
-            .text(xhr.responseText)
+            .text(error.message)
             .prop("hidden", false)
             .get(0).scrollIntoView({ block: "nearest" });
           updateButtons();
-        }
-      };
-
-      if (name !== "subscribe" && name !== "unsubscribe" && name !== "reopen") {
-        ajaxSettings.data = { text: content.find("textarea").val() };
-      }
-
-      content.find("button[name]").prop("disabled", true);
-      $.ajax(ajaxSettings);
+        });
     });
 
     content.find("textarea").on("input", function (e) {