const content = $("#sidebar_content"),
page = {};
- const noteIcons = {
- "new": L.icon({
- iconUrl: OSM.NEW_NOTE_MARKER,
- iconSize: [25, 40],
- iconAnchor: [12, 40]
- }),
- "open": L.icon({
- iconUrl: OSM.OPEN_NOTE_MARKER,
- iconSize: [25, 40],
- iconAnchor: [12, 40]
- }),
- "closed": L.icon({
- iconUrl: OSM.CLOSED_NOTE_MARKER,
- iconSize: [25, 40],
- iconAnchor: [12, 40]
- })
- };
-
page.pushstate = page.popstate = function (path, id) {
OSM.loadSidebarContent(path, function () {
const data = $(".details").data();
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") {
+ const textarea = content.find("textarea");
+ if (textarea.length) {
+ data.set("text", 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) {
const data = $(".details").data();
if (data) {
- const hashParams = OSM.parseHash(window.location.hash);
+ const hashParams = OSM.parseHash();
map.addObject({
type: "note",
id: parseInt(id, 10),
latLng: L.latLng(data.coordinates.split(",")),
- icon: noteIcons[data.status]
+ icon: OSM.getMarker({ icon: `${data.status}_NOTE_MARKER`, shadow: false, height: 40 })
}, function () {
if (!hashParams.center && !skipMoveToNote) {
const latLng = L.latLng(data.coordinates.split(","));