-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(form, method, url, include_data) {
+ var data;
- page.pushstate = page.popstate = function(path) {
- $("#history_tab").addClass("current");
- $('#sidebar_content').load(path, page.load);
- };
+ $(form).find("#comment-error").prop("hidden", true);
+ $(form).find("input[type=submit]").prop("disabled", true);
- page.load = function() {
- map.addLayer(group);
+ if (include_data) {
+ data = { text: $(form.text).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, xhr_status, http_status) {
+ $(form).find("#comment-error").text(xhr.responseText);
+ $(form).find("#comment-error").prop("hidden", false);
+ $(form).find("input[type=submit]").prop("disabled", false);
}
});
+ }
- changesets.sort(function (a, b) {
- return b.bounds.getSize() - a.bounds.getSize();
+ function initialize() {
+ content.find("input[name=comment]").on("click", function (e) {
+ e.preventDefault();
+ var data = $(e.target).data();
+ updateChangeset(e.target.form, data.method, data.url, true);
});
- 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(".action-button").on("click", function (e) {
+ e.preventDefault();
+ var data = $(e.target).data();
+ updateChangeset(e.target.form, data.method, data.url);
+ });
- $("[data-changeset]").on({
- mouseover: function () {
- highlightChangeset($(this).data("changeset").id);
- },
- mouseout: function () {
- unHighlightChangeset($(this).data("changeset").id);
+ content.find("textarea").on("input", function (e) {
+ var form = e.target.form;
+
+ 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;