X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/32645dd8565e7bbad75ab4a03a6b25c4f14e4bda..bcf75b0ae2588d38dc3d6615a0f61f044aad1223:/app/assets/javascripts/index/changeset.js?ds=sidebyside diff --git a/app/assets/javascripts/index/changeset.js b/app/assets/javascripts/index/changeset.js index 5c600fe87..75a1f7b4d 100644 --- a/app/assets/javascripts/index/changeset.js +++ b/app/assets/javascripts/index/changeset.js @@ -1,76 +1,84 @@ -OSM.ChangesetList = function(map) { - var page = {}; +OSM.Changeset = function (map) { + var page = {}, + content = $("#sidebar_content"), + currentChangesetId; - var group = L.featureGroup() - .on({ - mouseover: function (e) { - highlightChangeset(e.layer.id); - }, - mouseout: function (e) { - unHighlightChangeset(e.layer.id); - } + page.pushstate = page.popstate = function (path, id) { + OSM.loadSidebarContent(path, function () { + page.load(path, id); }); + }; - group.getLayerId = function(layer) { - return layer.id; + page.load = function (path, id) { + if (id) currentChangesetId = id; + initialize(); + addChangeset(currentChangesetId, true); }; - function highlightChangeset(id) { - group.getLayer(id).setStyle({fillOpacity: 0.5}); - $("#changeset_" + id).addClass("selected"); + function addChangeset(id, center) { + map.addObject({ type: "changeset", id: parseInt(id, 10) }, function (bounds) { + if (!window.location.hash && bounds.isValid() && + (center || !map.getBounds().contains(bounds))) { + OSM.router.withoutMoveListener(function () { + map.fitBounds(bounds); + }); + } + }); } - function unHighlightChangeset(id) { - group.getLayer(id).setStyle({fillOpacity: 0}); - $("#changeset_" + id).removeClass("selected"); - } + function updateChangeset(method, url, include_data) { + var data; - page.pushstate = page.popstate = function(path) { - $("#history_tab").addClass("current"); - $("#sidebar").removeClass("minimized"); - map.invalidateSize(); - $('#sidebar_content').load(path, page.load); - }; + content.find("#comment-error").prop("hidden", true); + content.find("button[data-method][data-url]").prop("disabled", true); - page.load = function() { - map.addLayer(group); + if (include_data) { + data = { text: content.find("textarea").val() }; + } else { + data = {}; + } - var changesets = []; - $("[data-changeset]").each(function () { - var changeset = $(this).data('changeset'); - if (changeset.bbox) { - changeset.bounds = L.latLngBounds([changeset.bbox.minlat, changeset.bbox.minlon], - [changeset.bbox.maxlat, changeset.bbox.maxlon]); - changesets.push(changeset); + $.ajax({ + url: url, + type: method, + oauth: true, + data: data, + success: function () { + OSM.loadSidebarContent(window.location.pathname, page.load); + }, + error: function (xhr) { + content.find("button[data-method][data-url]").prop("disabled", false); + content.find("#comment-error") + .text(xhr.responseText) + .prop("hidden", false) + .get(0).scrollIntoView({ block: "nearest" }); } }); + } - changesets.sort(function (a, b) { - return b.bounds.getSize() - a.bounds.getSize(); + function initialize() { + content.find("button[data-method][data-url]").on("click", function (e) { + e.preventDefault(); + var data = $(e.target).data(); + var include_data = e.target.name === "comment"; + updateChangeset(data.method, data.url, include_data); }); - for (var i = 0; i < changesets.length; ++i) { - var changeset = changesets[i], - rect = L.rectangle(changeset.bounds, - {weight: 2, color: "#ee9900", fillColor: "#ffff55", fillOpacity: 0}); - rect.id = changeset.id; - rect.addTo(group); - } + content.find("textarea").on("input", function (e) { + var form = e.target.form; - $("[data-changeset]").on({ - mouseover: function () { - highlightChangeset($(this).data("changeset").id); - }, - mouseout: function () { - unHighlightChangeset($(this).data("changeset").id); + if ($(e.target).val() === "") { + $(form.comment).prop("disabled", true); + } else { + $(form.comment).prop("disabled", false); } }); - }; - page.unload = function() { - map.removeLayer(group); - group.clearLayers(); - $("#history_tab").removeClass("current"); + content.find("textarea").val("").trigger("input"); + } + + page.unload = function () { + map.removeObject(); }; return page;