[#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.
This commit is contained in:
amercader 2013-06-14 17:37:44 +01:00
parent 7bf2c609e6
commit e4774e62a5
1 changed files with 6 additions and 4 deletions

View File

@ -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());
}
};