From e4774e62a54fe58121d6abcaa1bc98d5d644927a Mon Sep 17 00:00:00 2001 From: amercader Date: Fri, 14 Jun 2013 17:37:44 +0100 Subject: [PATCH] [#21] Fix i18n calls All the 'self' on the 'showError' function should be 'this', otherwise you will refer to the window. Also 'this.i18n' assumes an 'i18n' key in the module options. Looks like you are trying to pass some variables to the string template, note the sprintf-like syntax. --- ckanext/spatial/public/js/geojson_preview.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ckanext/spatial/public/js/geojson_preview.js b/ckanext/spatial/public/js/geojson_preview.js index 95f3f5a..19e5391 100644 --- a/ckanext/spatial/public/js/geojson_preview.js +++ b/ckanext/spatial/public/js/geojson_preview.js @@ -8,6 +8,9 @@ ckan.module('geojsonpreview', function (jQuery, _) { opacity: 0.7, fillOpacity: 0.1, weight: 2 + }, + i18n: { + 'error': _('An error occurred: %(text)s %(error)s') } }, initialize: function () { @@ -58,15 +61,15 @@ ckan.module('geojsonpreview', function (jQuery, _) { showError: function (jqXHR, textStatus, errorThrown) { if (textStatus == 'error' && jqXHR.responseText.length) { - self.el.html(jqXHR.responseText); + this.el.html(jqXHR.responseText); } else { - self.el.html(self.i18n('error', {text: textStatus, error: errorThrown})); + this.el.html(this.i18n('error', {text: textStatus, error: errorThrown})); } }, showPreview: function (geojsonFeature) { var self = this; - var gjLayer = L.geoJson(undefined, { + var gjLayer = L.geoJson(geojsonFeature, { style: self.options.style, onEachFeature: function(feature, layer) { var body = ''; @@ -80,7 +83,6 @@ ckan.module('geojsonpreview', function (jQuery, _) { layer.bindPopup(popupContent); } }).addTo(self.map); - gjLayer.addData(geojsonFeature); self.map.fitBounds(gjLayer.getBounds()); } };