]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - dist/handlebar_helpers.js
details page: addressline.isaddress is a boolean, not t/f string
[nominatim-ui.git] / dist / handlebar_helpers.js
index 6443d37e83c80149dbcd0502903e0b7cbd9532ce..7af3384df441c4818086e8d270bf6c2555ef7aa4 100644 (file)
@@ -1,3 +1,5 @@
+'use strict';
+
 function formatOSMType(sType, bExcludeExternal) {
   if (sType === 'N') return 'node';
   if (sType === 'W') return 'way';
@@ -12,8 +14,11 @@ function formatOSMType(sType, bExcludeExternal) {
 }
 
 Handlebars.registerHelper({
-  isaddresses_unused: function (aAddressLine) {
-    return ((aAddressLine.isaddress && aAddressLine.isaddress === 'f') ? 'notused' : '');
+  shortOSMType: function (sType) {
+    if (sType === 'node') return 'N';
+    if (sType === 'way') return 'W';
+    if (sType === 'relation') return 'R';
+    return '';
   },
   // { osm_type: 'R', osm_id: 12345 }
   // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
@@ -60,10 +65,22 @@ Handlebars.registerHelper({
 
     var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
 
+    var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id;
+    if (aFeature.category) {
+      sURL = sURL + '&class=' + aFeature.category;
+    }
+
     return new Handlebars.SafeString(
-      '<a href="details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id + '&class=' + aFeature.category + '">' + sTitleEscaped + '</a>'
+      '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
     );
   },
+  formatPlaceType: function (aPlace) {
+    var sOut = aPlace.class + ':' + aPlace.type;
+    if (aPlace.type && aPlace.type === 'administrative' && aPlace.place_type) {
+      sOut = sOut + ' (' + aPlace.place_type + ')';
+    }
+    return new Handlebars.SafeString(sOut);
+  },
   coverageType: function (aPlace) {
     return (aPlace.isarea ? 'Polygon' : 'Point');
   },
@@ -88,7 +105,7 @@ Handlebars.registerHelper({
     return (iLevel < 15 ? iLevel : '');
   },
   formatMapIcon: function (sIcon) {
-    if (!sIcon) return;
+    if (!sIcon) return '';
 
     var url = sIcon;
     if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
@@ -104,10 +121,13 @@ Handlebars.registerHelper({
       return s && s[0].toUpperCase() + s.slice(1);
     }
 
-    if (aPlace.type && aPlace.type === 'yes') {
+    if (aPlace.type && aPlace.type === 'yes' && aPlace.class) {
       return capitalize(aPlace.class.replace(/_/g, ' '));
     }
-    return capitalize(aPlace.type.replace(/_/g, ' '));
+    if (aPlace.type) {
+      return capitalize(aPlace.type.replace(/_/g, ' '));
+    }
+    return '';
   },
   formatSearchRank: function (iRank) {
     // same as
@@ -133,13 +153,10 @@ Handlebars.registerHelper({
     return 'other: ' + iRank;
   },
   tooManyHierarchyLinesWarning: function (aPlace) {
-    if (!aPlace.hierarchy) return;
+    if (!aPlace.hierarchy) return '';
 
-    var c = 0;
-    for (var type in aPlace.hierarchy) {
-      c = c + type.length + 1;
-    }
-    if (c < 500) return;
+    var c = Object.keys(aPlace.hierarchy);
+    if (c < 500) return '';
 
     return new Handlebars.SafeString(
       '<p>There are more child objects which are not shown.</p>'
@@ -173,7 +190,9 @@ Handlebars.registerHelper({
 
     var select = $('<select>');
     var option = jQuery('<option>', { value: '', text: '--' });
-    if (typeof (iSelectedZoom) === 'undefined') option.attr('selected', 'selected');
+    if (typeof (iSelectedZoom) === 'undefined') {
+      option.attr('selected', 'selected');
+    }
     option.appendTo(select);
 
     jQuery.each(aZoomLevels, function (i, title) {