- // Redraw in selected style
- feature.layer.drawFeature(
- feature, feature.layer.styleMap.createSymbolizer(feature, "select")
- );
-
- // If the current object is the list, don't innerHTML="", since that could clear it.
- if ($("#browse_content").firstChild == browseObjectList) {
- $("#browse_content").removeChild(browseObjectList);
- } else {
- $("#browse_content").empty();
- }
-
- $("#browse_content").html(JST["templates/browse/feature"]({
- name: featureNameSelect(feature),
- url: "/browse/" + featureType(feature) + "/" + feature.osm_id,
- attributes: feature.attributes
- }));
-
- $("#browse_content").find("a.browse_show_list").click(loadObjectList);
- $("#browse_content").find("a.browse_show_history").click(loadHistory);
-
- // Stash the currently drawn feature
- browseActiveFeature = feature;
- }
-
- function loadHistory() {
- $(this).attr("href", "").text(I18n.t('browse.start_rjs.wait'));
-
- var feature = browseActiveFeature;
-
- $.ajax({
- url: "/api/" + OSM.API_VERSION + "/" + featureType(feature) + "/" + feature.osm_id + "/history",
- success: function (xml) {
- if (browseActiveFeature != feature || $("#browse_content").firstChild == browseObjectList) {
- return;
- }
-
- $(this).remove();
-
- var history = [];
- var nodes = xml.getElementsByTagName(featureType(feature));
- for (var i = nodes.length - 1; i >= 0; i--) {
- history.push({
- user: nodes[i].getAttribute("user") || I18n.t('browse.start_rjs.private_user'),
- timestamp: nodes[i].getAttribute("timestamp")
- });
- }
-
- $("#browse_content").append(JST["templates/browse/feature_history"]({
- name: featureNameHistory(feature),
- url: "/browse/" + featureType(feature) + "/" + feature.osm_id,
- history: history
- }));
- }.bind(this)
- });
-
- return false;
- }
-
- function featureType(feature) {
- if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
- return "node";
- } else {
- return "way";
- }
- }
-
- function featureTypeName(feature) {
- if (featureType(feature) == "node") {
- return I18n.t('browse.start_rjs.object_list.type.node');
- } else if (featureType(feature) == "way") {
- return I18n.t('browse.start_rjs.object_list.type.way');
- }
- }
-
- function featureName(feature) {
- var lang = $('html').attr('lang');
- if (feature.attributes['name:' + lang]) {
- return feature.attributes['name:' + lang];
- } else if (feature.attributes.name) {
- return feature.attributes.name;
- } else {
- return feature.osm_id;
- }
- }
-
- function featureNameSelect(feature) {
- var lang = $('html').attr('lang');
- if (feature.attributes['name:' + lang]) {
- return feature.attributes['name:' + lang];
- } else if (feature.attributes.name) {
- return feature.attributes.name;
- } else if (featureType(feature) == "node") {
- return I18n.t("browse.start_rjs.object_list.selected.type.node", { id: feature.osm_id });
- } else if (featureType(feature) == "way") {
- return I18n.t("browse.start_rjs.object_list.selected.type.way", { id: feature.osm_id });
- }
- }
-
- function featureNameHistory(feature) {
- var lang = $('html').attr('lang');
- if (feature.attributes['name:' + lang]) {
- return feature.attributes['name:' + lang];
- } else if (feature.attributes.name) {
- return feature.attributes.name;
- } else if (featureType(feature) == "node") {
- return I18n.t("browse.start_rjs.object_list.history.type.node", { id: feature.osm_id });
- } else if (featureType(feature) == "way") {
- return I18n.t("browse.start_rjs.object_list.history.type.way", { id: feature.osm_id });
- }
- }
-
- function setStatus(status) {
- $("#browse_status").html(status);
- $("#browse_status").show();
- }
-
- function clearStatus() {
- $("#browse_status").html("");
- $("#browse_status").hide();
- }