-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;
};
- function highlightChangeset(id) {
- group.getLayer(id).setStyle({fillOpacity: 0.5});
- $("#changeset_" + id).addClass("selected");
- }
+ page.load = function(path, id) {
+ if(id)
+ currentChangesetId = id;
+ initialize();
+ addChangeset(currentChangesetId, true);
+ };
- function unHighlightChangeset(id) {
- group.getLayer(id).setStyle({fillOpacity: 0});
- $("#changeset_" + id).removeClass("selected");
+ function addChangeset(id, center) {
+ var bounds = map.addObject({type: 'changeset', id: parseInt(id)}, function(bounds) {
+ if (!window.location.hash && bounds.isValid() &&
+ (center || !map.getBounds().contains(bounds))) {
+ OSM.router.withoutMoveListener(function () {
+ map.fitBounds(bounds);
+ });
+ }
+ });
}
- page.pushstate = page.popstate = function(path) {
- $("#history_tab").addClass("current");
- $("#sidebar").removeClass("minimized");
- map.invalidateSize();
- $('#sidebar_content').load(path, page.load);
- };
-
- page.load = function() {
- map.addLayer(group);
+ function updateChangeset(form, method, url, include_data) {
+ $(form).find("input[type=submit]").prop("disabled", true);
+ 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);
}
});
+ }
- 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);
+ });
+
+ 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);
}
});
+
+ content.find("textarea").val('').trigger("input");
};
page.unload = function() {
- map.removeLayer(group);
- group.clearLayers();
- $("#history_tab").removeClass("current");
+ map.removeObject();
};
return page;
-};
+};
\ No newline at end of file